JSON parsing from an API and do something with it: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
No edit summary
Line 1: Line 1:
Using the Twitter API as an example. More particularly, we are fetching the most recent tweets containing the #cheese hashtag. See the [[http://apiwiki.twitter.com|Twitter API doc]] for more information.
Using the Twitter API as an example. More particularly, we are fetching the most recent tweets containing the #cheese hashtag. See the [http://apiwiki.twitter.com|Twitter API doc] for more information.


<source lang="python">
<source lang="python">

Revision as of 14:37, 21 January 2011

Using the Twitter API as an example. More particularly, we are fetching the most recent tweets containing the #cheese hashtag. See the API doc for more information.

import urllib2, json

url = 'http://search.twitter.com/search.json?q=%23cheese'
f = urllib2.urlopen(url)
data = json.load(f)

for r in data['results']:
    print r['from_user'] + ' says "' + r['text'] + '"'