Python 使用 tweepy 返回用户推文
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25588272/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Return a users tweets with tweepy
提问by user8028
I am using tweepy and python 2.7.6 to return the tweets of a specified user
我正在使用 tweepy 和 python 2.7.6 返回指定用户的推文
My code looks like:
我的代码看起来像:
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
However this yields a set of messages which look like<tweepy.models.Status object at 0x7ff2ca3c1050>
然而,这会产生一组看起来像的消息<tweepy.models.Status object at 0x7ff2ca3c1050>
Is it possible to print out useful information from these objects? where can I find all of their attributes?
是否可以从这些对象中打印出有用的信息?我在哪里可以找到它们的所有属性?
采纳答案by alecxe
Unfortunately, Statusmodel is not really well documented in the tweepydocs.
不幸的是,Status模型是不是真的很好的证明tweepy文档。
user_timeline()method returns a list of Statusobject instances. You can explore the available properties and methods using dir(), or look at the actual implementation.
user_timeline()方法返回Status对象实例的列表。您可以使用 探索可用的属性和方法dir(),或查看实际实现。
For example, from the source code you can see that there are author, userand other attributes:
例如,从源代码中可以看到有author,user和其他属性:
for status in stuff:
print status.author, status.user
Or, you can print out the _jsonattribute value which contains the actual response of an API call:
或者,您可以打印出_json包含 API 调用实际响应的属性值:
for status in stuff:
print status._json

