Twitter API

Another member of the group retrieved the twitter API. We were provided with a consumer key, consumer secret, access token and access token secret which were all needed for the code.

We followed a tutorial on Codasign, which took us through each step to create the code. Unlike the instagram one,  we required a library to add onto processing. The twitter 4j library allowed us to use twitter’s API in processing. This was downloaded and then imported at the top of the sketch.

Screen Shot 2016-03-23 at 12.35.15 p.m..png

Outside the setup, the variables were declared. In this case, the ‘string’/ text was declared. The code would then search twitter for any tweets containing “digital art” (this could be changed or look for multiple search terms). The int holds numbers and holds the number of current tweets. The tweets are stored in these until the draw.

Screen Shot 2016-03-23 at 12.44.37 p.m..png

Within the set up, the consumer key etc was needed to search through twitter. The setup was also where the functions happened, and it allowed the tweets to be retrieved before drawing them in the draw.

Screen Shot 2016-03-23 at 12.35.34 p.m..png

The functions are outside the draw, and this was the function that searched twitter and got the tweets.

Screen Shot 2016-03-23 at 12.36.01 p.m..png

The next function refreshed the tweets and got new ones, while it was already getting the original tweets, so it is constantly loading and retrieving new tweets. The delay is 30 seconds, so it only refreshes and gets the updated tweets after 30 seconds.

Screen Shot 2016-03-23 at 12.36.23 p.m..png

The draw then takes the tweets and displays them one at a time, fading in and out at random positions on the screen. They change and reload to new ones after 30 seconds. (The delay can be changed so that the tweets are refreshed quicker.

The if statement controls the refreshing of the tweets in the draw. It constantly goes back to zero so it starts to draw them over again.

Screen Shot 2016-03-23 at 12.35.50 p.m..png

When the code runs it is displayed like this:

Screen Shot 2016-03-23 at 1.02.47 p.m..png

The display of the tweets is similar to what we wanted. We just needed to combine the instagram and twitter codes together. As we decided instead of separate projections of instagram and twitter we were going to use one projection and one sketch.

Codasign. (2016) Processing and Twitter. [Online] Available from: http://codasign.com/tutorials/processing-and-twitter/processing-and-twitter-getting-started/ [Accessed 7th March 2016]

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s