Twitter and Instagram feeds in Processing

InstaTweet-000285

I spent today working out how to get data from the Twitter and Instagram APIs into Processing. It wasn’t easy, but it’s done and I have a nice thing that has been grabbing Instagrams tagged #selfie and combining them with tweets that contain #myself, example shown above.

It’s been such a slog that it’s actually hard to write up. The twitter bit was done beginning with Jer Thorp’s code example here, and making some changes to the twitter4j import. At the bottom of that blog post there are a few important tips, and you should change the following in that code:

// 1. added import java.util.*; (for Date support)
// 2. Replace Tweet with Status
// 3. Replace query.setRpp(100); with query.setCount(100);

It’s also worth noting that changing the way that Twitter4J is installed is an important step to getting it to work: details here.

The Instagram data import took longer to figure out. Firstly, a lot of examples you’ll find online lead you to Francis Li’s http library, and while this looks the part, I couldn’t get it to work on my system. In the end, I used the http library recommended on the Processing libraries page, and modified the JSON example here to search for a hashtag. Instagram’s JSON stream comes back differently to the examples that used Francis Li’s library too, so it took me a while to sift through the stream to get to the bits I needed. The code is here, so feel free to use it and best of luck to you.