#119: Follow, Like and Retweet With Tweepy
Tweepy is not only good for housekeeping, but we can also use it for more positive interactions on Twitter. Let's see how we can like and retweet tweets.
Preparation
As with the examples before, we need the user authentication tokens to work on behalf of that user. We use the V2 endpoints for this post:
As a reminder, with this code you can get the user id from a screen name:
id of user '@ThePSF': 63873759
Follow an account
You can follow an account with the follow() method:
user followed? True
Unfollow an account
If you have called the follow() method with the wrong id, you can correct this with the unfollow() method.
user followed? False
Like a tweet
We can like a tweet with the method like():
liked the tweet? True
Retweet a tweet
The names for the methods in Tweepy are predictable, that means we can us the retweet() method to make a retweet:
retweeted the tweet? True
Send a tweet with the V2 client
So far, we only used the V1 API to send a tweet. With the V2 client we can write a tweet with the create_tweet() method:
Tweet #1501292904916021249 created
The V2 endpoint offers all the new features that Twitter introduced lately. The Tweepy documentation offers a good overview on all the settings you can use.
Working with bookmarks
Twitter added an endpoint for bookmarks that I explore in this post.
Parting Thoughts
Over the last 10 weeks, I've been working intensively with the Twitter API and Tweepy. I have covered all the parts that I think you need to work effectively with Tweepy. Some parts like the filtering rules for streams offer nasty surprises.
Nonetheless, the Twitter API works well, and you should now have all the pieces together to create your own Twitter bot. For the time being, this is where I stop. I figured out what I need to know about the capabilities of the Twitter API and now is time for something different.
I hope you enjoyed the journey.