A Script to Download Images From Twitter

Ahmet Kucuk
Dec 30, 2015 · 1 min read

Recently, I decided to pull images from Twitter to use in my Deep Neural Network project. Apparently, it is not a good idea because of the noisy data which might be the topic of another post. In this post, I will share a simple Java Code that allow you to download images from Twitter.

The Code is available in Github.

To run the code, you need to have a Twitter Application Account so that you can get appropriate authentication token for the Twitter’s API.

I want to explain the code little. The code is using Twitter’s Streaming API with Twitter’s Java Client.

Once you get the authentication token, you just need to decide which terms will be tracked. And this is all. The Code will check if the tweet has appropriate image and if there is, it will download the image in a separate thread that you can specify the maximum number of threads. It will also take care of duplicate urls which is important because I saw in my own tests, there are lots of tweets with same image url.

If you want to specify other constraints like location, it is fairly simple and can be found in Twitter’s Streaming API documentation.

It is very naive approach to get images and not tested very well. I am sharing the code because It worked for me and it might be a starting point for your project!

Ahmet Kucuk

Ahmet’s Personal Blog

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store