Python – API.favorites() in Tweepy
Twitter is a popular social network where users share messages called tweets. Twitter allows us to mine the data of any user using Twitter API or Tweepy. The data will be tweets extracted from the user. The first thing to do is get the consumer key, consumer secret, access key and access secret from twitter developer available easily for each user. These keys will help the API for authentication.
API.favorites()
The favorites()
method of the API
class in Tweepy module is used to get the liked statuses of a user, 20 at a time.
Syntax : API.favorites(id / user_id / screen_name)
Parameters : Only use one of the 3 options:
- id : specifies the ID or the screen name of the user.
- user_id : specifies the ID of the user, useful to differentiate accounts when a valid user ID is also a valid screen name.
- screen_name : specifies the screen name of the user, useful to differentiate accounts when a valid screen name is also a user ID.
Returns : a list of objects of class Status
Example 1 : Using favorites()
method without any parameter returns the likes statuses of the authenticated user.
import tweepy
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
favorites = api.favorites()
for status in favorites:
print (status.user.screen_name)
|
Output :
oldschoolmonk
notcapnamerica
sardesairajdeep
Artie_Pavlov
BabitaPhogat
notcapnamerica
DerekGreaser
MarkDice
AOC
notcapnamerica
coolfunnytshirt
AOC
CNMparody
marwilliamson
YourAnonCentral
SanjeevSanskrit
4TheCulture____
tify330
AOC
matthewferner
Example 2 : Using favorites()
method with the parameter screen name.
screen_name = "geeksforgeeks"
favorites = api.favorites(screen_name)
for status in favorites:
print (status.user.screen_name)
|
Output :
abhinav26925233
adieti_sharma
vc90
KasatNiraj
harshitabambure
vc90
dns4u
bhagat_dinesh
BafnaTweets
malgattirajat
adieti_sharma
c_deep07
Its_username_yo
Rituraj97082167
Martial_Coder
baniya_buddy_
burgerNpizza
YehTuneKyaKiya
tweetsbybabua
shivankgtm
Last Updated :
08 Jun, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...