Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter API not showing old tweets?

Tags:

twitter

I have a problem with twitter API. I tweeted in the past (around 400) but recently I haven't tweeted anything. When I try to fetch tweets by me using the twitter api, there are no results. How can I retrieve the older tweets?

like image 560
gamehelp16 Avatar asked Jan 07 '13 08:01

gamehelp16


1 Answers

This elaborates on @bennett-mcelwee 's answer where getting up to 3200 most recent user tweets can be done in series of API calls. Currently the max # of tweets you can get by a user in 1 request is 200, using the GET statuses/user_timeline API call. To get all tweets a user has posted on their timeline do the following:

STEP 1

Make a GET call to this endpoint passing parameter count=200.

STEP 2

From the returned data in step 1, get the ID of the last tweet

Make the same GET call but this time pass in parameter max_id= followed by the ID of last tweet returned form the first call, or -1. So for example max_id=9987999

STEP 3

Repeat step 2 until you don't get any new(older) data.

For my purpose I was able to do this in Ruby using https://github.com/sferik/twitter

Once a client object is instantiated, it's as simple as:

tweets = client.user_timeline('foobar', count: 200)
max_id = tweets.last.id - 1
tweets << client.user_timeline('foobar', count: 200, max_id: max_id)

From here you get idea and it's fairly trivial to write a loop until you've gotten all the tweets you can grab from the API.

like image 121
lacostenycoder Avatar answered Dec 26 '22 07:12

lacostenycoder