Using the Twitter REST API to get images tweeted by a user


#1

I’m using the Twitter REST API to try and get only images for a specific user.

If I use statuses/user_timeline, then I get a mixture of of textual tweets and images, and the results are limited to 200. This means that I can end up with about 10 images per 200 results, because of the text tweets involved in the returned data.

What I’m trying to do instead, is use tweets/search with the From:Username filter:images keywords. But I have encountered an issue: On twitter.com, the search term > From:Gregory_Onye filter:images returns a few results, but when using the API I receive only 1 result…

Can anyone help me with this issue?

See below for search metadata:

"search_metadata":  {
    "completed_in": 0.03,
    "max_id": 579641668875452400,
    "max_id_str": "579641668875452416",
    "query": "From%3AGregory_Onye+filter%3Aimages",
    "refresh_url": "?since_id=579641668875452416&q=From%3AGregory_Onye%20filter%3Aimages&include_entities=1",
    "count": 100,
    "since_id": 0,
    "since_id_str": "0"
  }

#2

This is because the search API only goes back a few days. The full search of all Tweets ever posted is not exposed in the REST API.


#3

So the solution to this issue would be to simply use ‘https://api.twitter.com/1.1/statuses/user_timeline.json’ with no ‘q’ string, instead of ‘https://api.twitter.com/1.1/search/tweets.json’ and save the results that contain ‘media’?


#4

That should work, yes.