samedi 23 juin 2012

Using Twitter Search API

Twitter Search API allows us to run searches against the real-time index of recent Tweets. 
Here is sample Python code showing how to search in twitter without using any Python third party library like twython, tweepy, python-twitter, tweetstream, etc.
Twitter search URL is we will be using json as format for requested data.
import urllib
import json
query = "euro+2012" 
lat = str(37.781157)        
lng = str(-122.398720)
rd  = str(10000)
search = urllib.urlopen(""+lat+","+lng+","+rd+"mi"+"&q="+query)
dict = json.loads(
for result in dict["results"]:         
    print result, "\n"
    print "*******************************" 
Printing result["text"] should give you the corresponding tweet message. To get the location from where the tweet was posted user result["location"].
You can get more information about the parameters (e.g. size of the returned result) to use in your search query here.

Aucun commentaire:

Enregistrer un commentaire