Reputation: 969
This https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-favorites-list works well with PHP.I want to know how can I use it with tweepy or any of the python modules?
Upvotes: 4
Views: 5166
Reputation: 429
What you're looking to do can be achieved with Tweepy. You can use cursor to search for all of the retweets from a user, then extract the information you need. The structure of the repsonse is very similar to the response from the php api you are looking at.
To use the following code tweepy needs access to your developer accounts app, you can find a basic guide on how to do this on their documentation.
Code For Searching:
# This variable hold the username or the userid of the user you want to get favorites from
# This needs to be the users unique username
User = "@StackOverflow"
# Cursor is the search method this search query will return 20 of the users latest favourites just like the php api you referenced
for favorite in tweepy.Cursor(api.favorites, id=User).items(20):
# To get diffrent data from the tweet do "favourite" followed by the information you want the response is the same as the api you refrenced too
#Basic information about the user who created the tweet that was favorited
print('\n\n\nTweet Author:')
# Print the screen name of the tweets auther
print('Screen Name: '+str(favorite.user.screen_name.encode("utf-8")))
print('Name: '+str(favorite.user.name.encode("utf-8")))
#Basic information about the tweet that was favorited
print('\nTweet:')
# Print the id of the tweet the user favorited
print('Tweet Id: '+str(favorite.id))
# Print the text of the tweet the user favorited
print('Tweet Text: '+str(favorite.text.encode("utf-8")))
# Encoding in utf-8 is a good practice when using data from twitter that users can submit (it avoids the program crashing because it can not encode characters like emojis)
Implement that code under your OAuth for authentication code
Upvotes: 7