Python + bearer + search


I got a bearer_token properly, and now trying to test search through GET request.

It fails with error: urllib2.HTTPError: HTTP Error 400: Bad Request

Should something like this work:

    req = urllib2.Request('')
    req.add_header('User-Agent', 'test')
    req.add_header('Authorization: Bearer ', bearer_token)
    req.add_header("Accept-Encoding", "gzip")
    response1 = urllib2.urlopen(req)

Premium API endpoint

Something like that generally should work but I think you might be accidentally setting an HTTP header with the “key” "Authorization: Bearer " rather than the key being “Authorization” and the value being "Bearer " + bearer_token


Thanks Taylor!! :slight_smile:

Wrongly left http instead of https, and as you pointed Authorization key was wrong.

Corrected (in case someone needs):

query = urllib.urlencode([(‘q’,‘test query’)])

url = '' % query
req = urllib2.Request(url)
req.add_header('Authorization', 'Bearer '+ bearer_token + '')
req.add_header('User-Agent', 'Test Twitter Client')