【发布时间】:2015-01-31 15:40:01
【问题描述】:
我正在使用 Tweepy 获取 @UserName 发布的所有推文。这是下面的代码
import urllib, json
import sys
import tweepy
from tweepy import OAuthHandler
def twitter_fetch(screen_name = "prateek",maxnumtweets=10):
consumer_token = "" #Keys removed for security
consumer_secret = ""
access_token = ""
access_secret = ""
auth = tweepy.OAuthHandler(consumer_token,consumer_secret)
auth.set_access_token(access_token,access_secret)
api = tweepy.API(auth)
for status in tweepy.Cursor(api.user_timeline,id=screen_name).items(1):
print status['statuses_count']
print '\n'
if __name__ == '__main__':
twitter_fetch('BarackObama',200)
如何正确解析 JSON 以读取该特定用户的状态数?
【问题讨论】:
-
如果您将查询的 JSON 输出发布到 pastebin 上会很有帮助?
-
@SamCyanide pastebin.com/C1RiGUtF - 绝对不变的输出
-
所以你想计算一个特定人的推文总数吗?这就是你要找的全部吗?无需迭代某些东西,就像编写简单的代码行一样简单,tweepy 将为您完成所有工作。告诉我你是否也在寻找同样的东西
标签: python json twitter tweepy