twitter retweet user id api python

自作多情 提交于 2019-12-24 00:57:22

问题


using the twitter api with python, I need to know how to get all the user ids of all the people that retweeted a tweet.

I went here: https://dev.twitter.com/docs/api/1/get/statuses/%3Aid/retweeted_by

but I do not know how to put that into python.

here is my code so far:

from twitter import *
t = Twitter(auth=OAuth(....))
twitter = t.statuses.user_timeline.snl()

twitter[0]['text']           # gets the tweet
twitter[0]['retweet_count']  # gets the number of retweets

what is my next line to get the IDs of all the users who retweeted?


回答1:


You should use retweets_of_me for twitter API 1.1, retweeted_by is deprecated and doesn't work.

Here's an example:

from twitter import *

t = Twitter(auth=OAuth(...))

tweets = t.statuses.user_timeline.snl()

for tweet in tweets:
    retweets = t.statuses.retweets_of_me(since_id=str(tweet['id']), max_id=str(tweet['id']))
    print retweets

Hope that helps.



来源:https://stackoverflow.com/questions/17154697/twitter-retweet-user-id-api-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!