用tweepy返回用户的tweets

2024-05-16 13:03:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用tweepy和python 2.7.6返回指定用户的tweets

我的代码看起来像:

import tweepy

ckey = 'myckey'
csecret = 'mycsecret'
atoken = 'myatoken'
asecret = 'myasecret'



auth = tweepy.OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)

api = tweepy.API(auth)

stuff = api.user_timeline(screen_name = 'danieltosh', count = 100, include_rts = True)

print stuff

但是这会产生一组看起来像<tweepy.models.Status object at 0x7ff2ca3c1050>的消息

是否可以从这些对象中打印出有用的信息?在哪里可以找到它们的所有属性?


Tags: 代码用户importauthapitweetsstufftweepy
1条回答
网友
1楼 · 发布于 2024-05-16 13:03:54

不幸的是,Status模型并没有在^{} docs中得到很好的记录。

^{}方法返回Status对象实例的列表。您可以使用^{}探索可用的属性和方法,或者查看actual implementation

例如,从源代码中可以看到有authoruser和其他属性:

for status in stuff:
    print status.author, status.user

或者,您可以打印出包含API调用的实际响应的_json属性值:

for status in stuff:
    print status._json

相关问题 更多 >