DEV Community

Cover image for Creating a Twitter bot in Python using Twitter APIv2 πŸš€πŸš€

Creating a Twitter bot in Python using Twitter APIv2 πŸš€πŸš€

Dhravya on October 06, 2022

When I was migrating @poet_this twitter bot to use the Twitter API v2, I wasn't able to find any good tutorials that do it, atleast none that worke...
Collapse
 
andypiper profile image
Andy Piper

Nice post, thanks for sharing! It is a little different, but if you don’t currently need to upload media for your bot, I’d recommend using OAuth 2.0 for your user authentication (Twitter is moving away from OAuth 1.0A in general for the v2 APIs) - what you’ve got here will work fine, but if your bot in the future needs access to specific new scopes for new features, it will need to use OAuth 2.0.

Collapse
 
dhravya profile image
Dhravya

Ohh- I didn't know that

This tutorial has a bit of the code i wrote for the twitter bot, which does need to upload media, which is probably why I wrote that bit a couple months ago.

Thanks for the feedback! Really appreciate it.

Collapse
 
dhravya profile image
Dhravya

Hey Andy! sorry for reaching out to you like this - but I figured you're the best person to ask. I am aware that you don't work at twitter now, but the understanding of the API might help me.

So, twitter keeps banning the bot for unsolicited mentions. I'm using the same exact code for @poet_this, is there anything that you think im doing wrong?

Your help would be insanely useful πŸ™ Ive been struggling with this since almost a month now

Collapse
 
andypiper profile image
Andy Piper

Unfortunately I don’t know how the anti spam system is configured now so I can only suggest removing mentions from the bot. Otherwise you’ll have to ask Elon πŸ‘Ž

Collapse
 
devgancode profile image
Ganesh Patil

Great article @dhravya ✌

Collapse
 
dhravya profile image
Dhravya

Thank you!

Collapse
 
farandg profile image
Comment marked as low quality/non-constructive by the community. View Code of Conduct
GF

Seriously ? No part of the code works and it's "great" ? I'm starting to suspect this fraudster has friends helping him...

Collapse
 
dhravya profile image
Dhravya

code doesn't work? fraudster? lolll

and yes, I do have friends, because I'm not the type of person who would create a Dev account and try everything they can to hurt a random person.

if you don't like my blogs, don't read them! starting to think you're just jealous

Thread Thread
 
farandg profile image
Comment marked as low quality/non-constructive by the community. View Code of Conduct
GF

Devolving to grade-school comebacks now, are we ? You're as crap at that as you are at code. Did you get help from your little brother?
I expose you so I must be jealous, right ? Truth is just don't like little shits like you.

Thread Thread
 
dhravya profile image
Dhravya

the fact that I'm talking respectfully and you're not, just proves my point

Thread Thread
 
farandg profile image
GF

Your point being that you don't have one. Not the hardest thing to prove, mate...

Collapse
 
edson profile image
Edson Bittencourt

Hi @dhravya, great job. I think there's a mistake in environment vars. The tutorial says to create a file and declare ACCESS_TOKEN, but it's loading OAUTH_TOKEN in the code.

Collapse
 
dhravya profile image
Dhravya

Oops my bad! I'll edit that bit

Collapse
 
farandg profile image
GF

It's nearly four months later and you still haven't. Do you need help understanding your mistake ?

Thread Thread
 
dhravya profile image
Dhravya

you literally just created an account to insult me lmao get a life

Thread Thread
 
farandg profile image
Comment marked as low quality/non-constructive by the community. View Code of Conduct
GF

Yup! I thrive in putting little shits like you back in their place. Your disgracing the coder community

Thread Thread
 
dhravya profile image
Dhravya

ah yes the gatekeeper

Thread Thread
 
farandg profile image
GF

I wouldn't call myself that. I don't have your arrogance, you see...
I just spot frauds

Collapse
 
dhravya profile image
Dhravya

I'm planning to write more tutorials and content in the near future.

If you guys have any queries regarding this tutorial, feel free to ask here in the comments!

Collapse
 
farandg profile image
GF

My request: please don't

Collapse
 
edson profile image
Edson Bittencourt

Great

Collapse
 
aneeqakhan profile image
Aneeqa Khan

Great article @dhravya

Collapse
 
todaydate_ profile image
Today's Date

Hi Bro Can You Give me Your Poet this bot codes ??