Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get tweet IDs (since_id, max_id) in tweepy (python)?

I want to know a way of getting tweet IDs to keep a check on what tweets have been displayed in the timeline of user in the python app I am making using tweepy.

There doesn't seem to be a way I get extract the tweet IDs or keep track of them. The parameter to keep check is since_id. Please if anyone could help.

like image 235
Dev Uberoi Avatar asked May 29 '12 18:05

Dev Uberoi


2 Answers

The tweepy library follows the twitter API closely. All attributes returned by that API are available on the result objects; so for status messages you need to look at the tweet object description to see they have an id parameter:

for status in api.user_timeline():
    print status.id

Store the most recent id to poll for updates.

like image 160
Martijn Pieters Avatar answered Oct 29 '22 12:10

Martijn Pieters


The max_id and since_id are parameters for the api.user_timeline() method.

Using the tweepy.Cursor() object might look something like this:

    tweets = []
    for tweet in tweepy.Cursor(api.user_timeline,
                       screen_name=<twitter_handle>,
                       since_id = <since_id>
                       ).items(<count>):
        tweets.append(tweet)
like image 44
Jared Wilber Avatar answered Oct 29 '22 12:10

Jared Wilber