Dev Uberoi
Dev Uberoi

Reputation: 149

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.

Upvotes: 6

Views: 17778

Answers (2)

Jared Wilber
Jared Wilber

Reputation: 6805

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)

Upvotes: 2

Martijn Pieters
Martijn Pieters

Reputation: 1124488

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.

Upvotes: 7

Related Questions