📜  Python – Tweepy 中的 API.favorites()

📅  最后修改于: 2022-05-13 01:54:27.470000             🧑  作者: Mango

Python – Tweepy 中的 API.favorites()

Twitter是一个流行的社交网络,用户在其中分享称为推文的消息。 Twitter 允许我们使用 Twitter API 或Tweepy挖掘任何用户的数据。数据将是从用户那里提取的推文。首先要做的是从 Twitter 开发人员那里轻松获得每个用户可用的消费者密钥、消费者秘密、访问密钥和访问秘密。这些密钥将帮助 API 进行身份验证。

API.favorites()

Tweepy 模块中API类的favorites()方法用于获取用户的点赞状态,一次 20 个。

示例 1:使用不带任何参数的favorites()方法返回经过身份验证的用户的点赞状态。

# import the module
import tweepy
  
# assign the values accordingly
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
  
# authorization of consumer key and consumer secret
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
  
# set access to user's access key and access secret 
auth.set_access_token(access_token, access_token_secret)
  
# calling the api 
api = tweepy.API(auth)
  
# getting the liked statuses
favorites = api.favorites()
  
# printing the screen names of the status posters
for status in favorites:
    print(status.user.screen_name)

输出 :

oldschoolmonk
notcapnamerica
sardesairajdeep
Artie_Pavlov
BabitaPhogat
notcapnamerica
DerekGreaser
MarkDice
AOC
notcapnamerica
coolfunnytshirt
AOC
CNMparody
marwilliamson
YourAnonCentral
SanjeevSanskrit
4TheCulture____
tify330
AOC
matthewferner

示例 2:使用参数屏幕名称的favorites()方法。

# screen name of the user
screen_name = "geeksforgeeks"
  
# getting the liked statuses
favorites = api.favorites(screen_name)
  
# printing the screen names of the status posters
for status in favorites:
    print(status.user.screen_name)

输出 :

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