Retweeters of a Twitter status in Tweepy

拟墨画扇 提交于 2019-12-04 13:02:25

问题


This is kindof a followup question to this question. I want to get the ID of the users that have retweeted a particular tweet.

I tried following the same technique but I'm getting an error. Here's the code:

import tweepy

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)

api = tweepy.API(auth)

firstTweet = api.user_timeline("github")[0]
print firstTweet.text
print firstTweet.id
results = api.retweeted_by(firstTweet.id) 
print results

This returns the 1st tweet and also the tweet ID. It then gives me the following error:

    Traceback (most recent call last):
  File "twitter_test.py", line 21, in <module>
    results = api.retweeted_by("357237988863913984") 
  File "/usr/local/lib/python2.7/dist-packages/tweepy-2.1-py2.7.egg/tweepy/binder.py", line 197, in _call
    return method.execute()
  File "/usr/local/lib/python2.7/dist-packages/tweepy-2.1-py2.7.egg/tweepy/binder.py", line 173, in execute
    raise TweepError(error_msg, resp)
tweepy.error.TweepError: [{u'message': u'Sorry, that page does not exist', u'code': 34}]

回答1:


retweeted_by is not a part of 1.1 twitter API. Switch to retweets:

results = api.retweets(firstTweet.id)

FYI, quote from docs:

GET statuses/retweeters/ids

Returns a collection of up to 100 user IDs belonging to users who have retweeted the tweet specified by the id parameter.

This method offers similar data to GET statuses/retweets/:id and replaces API v1's GET statuses/:id/retweeted_by/ids method.



来源:https://stackoverflow.com/questions/17724988/retweeters-of-a-twitter-status-in-tweepy

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