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 almost 2 years
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. -
Liam almost 9 yearswhat is the api.user_timeline?
-
Martijn Pieters almost 9 years@Liam: the Twitter
statuses/user_timeline
collection. Also see the Tweepy API documentation. -
semiflex almost 8 yearsBut where do you insert the since_id and max_id in the for loop?
-
Martijn Pieters almost 8 years@KrishanVadher: did you look at the documentation I linked to in my last comment?
-
semiflex almost 8 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 almost 8 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 almost 8 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 almost 8 yearsOhh urr. That wasn't me.
-
Martijn Pieters almost 8 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 about 6 yearsThis would look better if you formatted your inline a bit better with the multi-line tweepy.Cursor()
-
Jared Wilber about 6 years@Danijel-JamesW feel free to edit! Current formatting is according to my pep8 linter :)
-
Shahir Ansari almost 5 yearsthe
since_id
andmax_id
parameter are not working. No matter what id you put in there,it always return tweet replies from the latest tweet.