Teo*_*sel 3 python twitter tweepy python-3.x
这个https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-favorites-list适用于 PHP。我想知道如何将它与 tweepy 或任何的python模块?
您可以使用 Tweepy 实现您想要做的事情。您可以使用光标搜索用户的所有转推,然后提取您需要的信息。repsonse 的结构与您正在查看的 php api 的响应非常相似。
要使用以下代码,tweepy 需要访问您的开发者帐户应用程序,您可以在他们的文档中找到有关如何执行此操作的基本指南。
搜索代码:
# 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)
Run Code Online (Sandbox Code Playgroud)
在您的 OAuth 下实现该代码以进行身份验证代码
| 归档时间: |
|
| 查看次数: |
3375 次 |
| 最近记录: |