How to get tweet IDs (since_id, max_id) in tweepy (python)?
15,593
Solution 1
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.
Solution 2
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)
Related videos on Youtube
Author by
Dev Uberoi
Updated on July 13, 2022Comments
-
Dev Uberoi 6 monthsI 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. -
Liam over 7 yearswhat is the api.user_timeline? -
Martijn Pieters over 7 years@Liam: the Twitterstatuses/user_timelinecollection. Also see the Tweepy API documentation. -
semiflex over 6 yearsBut where do you insert the since_id and max_id in the for loop? -
Martijn Pieters over 6 years@KrishanVadher: did you look at the documentation I linked to in my last comment? -
semiflex over 6 yearsI did. I still can't seem to pull tweets after a certain status ID. This is what I have at the moment. How would I change it: max_id = 724916468975046656 for status in tweepy.Cursor(api.user_timeline,twitter).items(count).items(max_id): -
Martijn Pieters over 6 years@KrishanVadher:.items(num)limits the number of items retured; it does not let you find items before a given tweet ID. I'm not familiar with the Tweepy Cursor API however; perhaps you want to create a new question for this. -
Martijn Pieters over 6 years@KrishanVadher: so this is now worthy of a downvote? Because I couldn't help you in the comments? The answer doesn't use Tweepy Cursors. -
semiflex over 6 yearsOhh urr. That wasn't me. -
Martijn Pieters over 6 years@KrishanVadher: If that's the case then you have my apologies on that. This is an answer from almost 4 years ago with little activity, a sudden downvote very close to some follow-up comments certainly gives the impression that the two events are related. -
Danijel-James W almost 5 yearsThis would look better if you formatted your inline a bit better with the multi-line tweepy.Cursor() -
Jared Wilber almost 5 years@Danijel-JamesW feel free to edit! Current formatting is according to my pep8 linter :)
-
Shahir Ansari over 3 yearsthesince_idandmax_idparameter are not working. No matter what id you put in there,it always return tweet replies from the latest tweet.