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 ??