Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retweeters of a Twitter status in Tweepy

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}]
like image 260
Anil Avatar asked Jul 18 '13 13:07

Anil


People also ask

Which returns a single status specified by the ID parameter?

GET statuses/show/:id Returns a single Tweet, specified by the id parameter. The Tweet's author will also be embedded within the Tweet.

How do I find the location of a tweet using Tweepy?

In order to get the location we have to do the following : Identify the user ID or the screen name of the profile. Get the User object of the profile using the get_user() method with the user ID or the screen name. From this object, fetch the location attribute present in it.

How do you tell if a tweet is a retweet API?

If it's a retweet, the tweet will contain a property named retweeted_status . To be complete, retweeted_status will not appear if the tweet is not a retweet. More info at: Tweets.


1 Answers

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.

like image 126
alecxe Avatar answered Sep 22 '22 15:09

alecxe