I'm a starter in python.I use the following code to get tweets depending on a input query.
import urllib
import urllib2
import json
def getData(keyword):
url = 'http://search.twitter.com/search.json'
data = {'q': keyword, 'lang': 'en', 'result_type': 'recent'}
params = urllib.urlencode(data)
try:
req = urllib2.Request(url, params)
response = urllib2.urlopen(req)
jsonData = json.load(response)
tweets = []
for item in jsonData['results']:
tweets.append(item['text'])
return tweets
except urllib2.URLError, e:
self.handleError(e)
return tweets
tweets = getData("messi")
print tweet
but i get the following error in the above code. Name Error: global name 'self' is not defined. How can i correct this error?
self.and write a function calledhandleErrorto deal with the problem.twitterpackage, its on pip.