Question

I was was trying to send a request for retrieving a list of the top 10 trending topics by using the GET trends/places API provided by Twitter at https://dev.twitter.com/docs/api/1.1/get/trends/place. Here's the code for the same in Python:

import twitter

CONSUMER_KEY = ' XXXXXXXXXX'
CONSUMER_SECRET ='XXXXXXXXXXXX'
OAUTH_TOKEN = ' XXXXXXXXX'
OAUTH_TOKEN_SECRET = ' XXXXXXX'

auth = twitter.oauth.OAuth(OAUTH_TOKEN, OAUTH_TOKEN_SECRET,
                           CONSUMER_KEY, CONSUMER_SECRET)

twitter_api = twitter.Twitter(auth=auth)

WORLD_WOE_ID = 1

world_trends = twitter_api.trends.place(_id=WORLD_WOE_ID)

print world_trends

When I only try to print 'twitter_api', I get the following as the output:

<twitter.api.Twitter object at 0x39d9b50>

which means that I have successfully used OAuth credentials to gain authorization to query Twitter's API. Now, after I run the above code, here's the error that I get:

TwitterHTTPError: Twitter sent status 400 for URL: 1.1/trends/place.json using parameters: (id=1&oauth_consumer_key=%201FqhG77x7XaVjx6a1lnm2ip8G&oauth_nonce=3628940350753944768&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1399534257&oauth_token=%20337142662-QWaMBk6MCe5vM6to5tw3AR3cHChYc0e0yUnEB7lh&oauth_version=1.0&oauth_signature=%2BD0ZzXV8cMuc5S%2B9UKRJ85xF1wY%3D)
details: {"errors":[{"message":"Bad Authentication data","code":215}]}

From the error message, I figured that the error has got something to do with bad syntax(since I get an HTTP 400 error message). Also, when I try to use the example URL mentioned on https://dev.twitter.com/docs/api/1.1/get/trends/place, I still get the following error: {"errors":[{"message":"Bad Authentication data","code":215}]}

What seems to be the problem with the code? I've tried finding the root cause of the error, but have failed to find any significant lead.

Was it helpful?

Solution

Okay, so I tried reading the documentation. Tried going through the module's source code, but couldn't find anything suspicious. Talked to a couple of guys, no luck. Then today, I tried regenerating my authentication keys. The program now works successfully ! I don't really know how regenerating my keys solved the bug, but I do see that a lot of developers get the exact same error, and no one really knows what's wrong. So if you're one of them, just regenerate your authentication keys and that should make your code work.

OTHER TIPS

I was going through the same problem.I highly suggest to regenerate consumer key, secret key as well as the access tokens if you are doing it for the first time. With, a little bit of research I found out that it's always the same case.

Check your location id with the following and use the ID.

http://woeid.rosselliot.co.nz/lookup/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top