I am learning how to access the Twitter API, but get the error "urllib2.HTTPError: HTTP Error 400: Bad Request" when I run the simple code below:
import urllib2
import simplejson
url = "https://api.twitter.com/1.1/search/tweets.json?screen_name=twitterapi"
if __name__ == "__main__":
req = urllib2.Request(url)
opener = urllib2.build_opener()
f = opener.open(req)
json = simplejson.load(f)
for item in json:
print item.get("created_at") # this will get the section that is "Created At from JSON"
print item.get('text') # this will get the text (in Twitter, a Tweet)
I am unsure why - I have Googled around and can't seem to find why this is returning the Bad Request error. Thanks for any help!