我正在学习如何访问Twitter API,但得到错误" urllib2.HTTPError:HTTP错误400:错误请求"当我运行下面的简单代码时:
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)
我不确定为什么 - 我已经用Google搜索了,似乎无法找到为什么这会返回Bad Request错误。谢谢你的帮助!