samedi 2 avril 2011

Twitter XML structure

If we want to get the tweets from the twitterrequest we have to understand the structure of the XML twitter is sending us.
Here is an example of a "live" xml: http://api.twitter.com/1/statuses/user_timeline.xml?user_id=111370674

This is one XML request saved: user_timeline.xml

Processing reference: http://processing.org/reference/XMLElement.html

Referring back to the processing script in one of the former posts we see this:


XMLElement xml = new XMLElement(this, "http://twitter.com/statuses/user_timeline/8138312.rss");

//we can dive into the XML tree with the getChild();

XMLElement myChannel = xml.getChild(0);

//with getChild you can count the "nodes"

XMLElement[] tweets = myChannel.getChildren("item");

/*
with getChildren , you can search on the "name" of the t
ag, getting back an array: XMLElement array, for this you have to know the name of the array. In this case the name is "item" .

Then you get the node 0 of this "item", and ask for the content:
tweets[i].getChild(0).getContent();

(which are the tweet texts) these are Strings, so pieces of text.

*/



Remark, you can only do 150 request an hour to get tweets from one client (say a computer) So real time twitter streaming, showing new tweets immediately is not possible. Also gaming with extracting commands from tweets is too slow now.

Aucun commentaire:

Enregistrer un commentaire