Tag Archives: YQL

Network once again, now with YQL!

While fiddling with the Facebook network, GEXF and JSON parsing I remembered Yahoo! and its YQL Web Services. With it, you can get a JSON-formatted result from any, say, XML file out there. GEXF is XML.

The YQL query language isn’t that handy if you are interested only in a selection of nodes; the XPath filter is only for HTML files, curiosly enough. I wanted the whole story though, so no problem. Here is how the YQL Console shows the result:

YQL Console

With the REST query down below, you can e.g. transfer the JSON result to your local machine, in Unix like curl 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D%22http%3A%2F%2Fusers.tkk.fi%2Fsonkkila%2Fnetwork%2Ffbmini.gexf%22&format=json&callback=' > gexf.json

The structure is more deep than in the JSON that the Cytoscape D3.js Exporter returns, but the only bigger change the D3 code needs is to have new references from the links/edges to nodes.

Like the documentation of force.start() says,

On start, the layout initializes various attributes on the associated nodes. The index of each node is computed by iterating over the array, starting at zero.

This is fine, if the source and target attributes in the edge array apply to this. Here, they do not. Instead, the attributes reference the id attribute in the respective nodes. So I needed to change that, and excellent help was available.

So far so good, but using index numbers to access attribute values isn’t pretty and needs to be done differently. Maybe next time.

Tweettien uusiokäyttöä

Twitter on uutisvälineeni nro 1, lähes. Niinpä suosikkejakin tulee tallennettua usein. Säilön linkkejä kiinnostaviin juttuihin. Ne tuppaavat kuitenkin unohtumaan, koska eivät ole mukana uutissyötteissä, joita taas käyn läpi GReaderilla. Yhteys puuttuu. Twitterin OAuth-autentikointi on pelottanut sen verran, etten ole tarttunut toimeen.

Tällä viikolla satuin katsomaan tallenteen YUIConf 2011 -konferenssista. Siinä YQL engineer Paul Donnelly demoaa, miten YQL-konsolinäkymässä saa rakennettua oikeanlaisen REST-kyselyn Twitteriin siten, että ohjelmointirajapintaan pääsee käsiksi. Pelkällä Yahoo Pipesilla tämä ei onnistu, koska se ei tue OAuthia.

YQL-konsolilla homma on helppo, kunhan vaan on ensin hankkinut tarvittavat avaimet ja tokenit. Ne saa Twitteriltä, rekisteröit vain jonkin sovelluksen.

Videolla YQL-osuus alkaa n. 20 minuutin paikkeilla.

Hae esiin Data tables -osiosta twitter.favorites, klikkaa konsolin response-laatikon oikeaan ylänurkkaan ilmestyvää painiketta – ja saat eteesi lomakkeen, johon avaimet ja tokenit kopioidaan. Itselläni meni tuon painikkeen äkkäämiseen tovi; videosta ei saa ihan selvää, mihin kohtaan Paul sormellaan osoittaa.

Kun testi menee läpi, konsolin alalaidasta voi kopsata valmiin kyselyn. Se Yahoo Pipesin Fetch data -moduuliin, ja siitä sitten RSS-syötteen peruskentät kuntoon ja siirto GReaderiin.