A Script to Download Images From Twitter

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

    Ahmet Kucuk

    Written by

    Software Engineer in NYC

    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