Search code examples
twittertwitter-oauthtwitter-rest-api

How to get all images uploaded by the user?


Using Twitter API, I would like to fetch all images uploaded by a user who authenticated my application (OAuth). I've been digging API docs but couldn't find an easy way to do it.

Should I list all tweets, iterate over them, get every single tweet and see if it has a media entity? C'mon?


Solution

  • There's no specific media fetching endpoint in the Twitter API, so yes, you'd need to do something along those lines.

    • call the statuses/user_timeline.json endpoint and page through it (supports up to 3200 Tweets). I'd suggest using the ?tweet_mode=extended parameter, to ensure you get media entities for any longer Tweets
    • iterate through the Tweet objects, looking for any extended_entities objects (these contain images or videos)
    • grab the images from the URL inside the object