A Small Script to Grab and Parse Tweets

In the last game I made, I originally made a little Twitter feed appear (however, after a design, it was left out). I thought I’d provide a small script to grab and parse your tweets:

var url = "https://api.twitter.com/1/statuses/user_timeline.json"
		+"?include_entities=" + includeEntities
		+"&include_rts=" + includeRetweets
		+"&screen_name=" + screenName
		+"&count=" + count;

var www = new WWW (url);
yield www;
	
var jsonText = www.text.Replace("\\/","/").Replace("\\u","");
var jsonObject : JSONObject = new JSONObject(jsonText);

It’s pretty simple once you know how. In order to actually get the data from the jsonObject, you can user the following code to grab the text of the n-th tweet:

jsonObject[i]["text"].ToString().Replace("\"", "")

This script uses a JSONObject.cs file that you put into the /Plugin directory. You can find it in the Unity Asset Store.

Hope this helps somebody!

I just realized, should this go in the “Assets and Asset Store” section instead of here?