Twitter API Returns Error 215, Bad Authentication Data

Twitter error code 215: Bad Authentication Data

Twitter does not allow gathering of information without OAuth:

Twitter API error 215

Twitter API Post Request -- Error Code 215 Bad Authentication data

I ended up finding the fix for my problem. The main problem was I wasn't percent encoding my value for oauth_signature. However, even after that I was getting a new error, {"errors":[{"code":32,"message":"Could not authenticate you."}]}.

From the link I originally posted up above about creating the signature, you build the base parameter string from percent-encoding, and "&" joining an oauth dictionary like this:

url_params = {
"status": "Tweeting from the future."
}

oauth = {
"include_entities": "true",
"oauth_consumer_key": consumer_key,
"oauth_nonce": generate_nonce(),
"oauth_signature_method": "HMAC-SHA1",
"oauth_timestamp": 946684800 + time.time(),
"oauth_token": access_token,
"oauth_version": 1.0,
}

oauth.update(url_params)

base_string = percent_encode_and_join(oauth)

(The time value is odd because the micropython system time epoch starts in Jan 1st, 2000 instead of Jan 1st, 1970)

However when I was debugging the request using PostMan it was working. I realized that Postman couldn't know to add that include_entities entry when it is calculating the signature. Lo and behold when I removed that key from this dictionary, the error went away.

Refer to my repo up above for the code.

Twitter API error 215

So, it seems Twitter's latest API 1.1 does not allow access without authentication - even for data that is seemingly public...like the latest 3 tweets from a timeline.

The best article I have found on this (which gives a great solution) for read-access can be found here:

http://www.webdevdoor.com/php/authenticating-twitter-feed-timeline-oauth/

I have followed the steps in the article above and can confirm it works great.

An interesting point to note, is that now, because you have to use access tokens and secret keys; all requests must be made with a server-side script. Prior to this I was using jQuery to make an AJAX request on Twitters JSON API directly. Now, you must AJAX request a dynamic script on your own website, if you wish to go down a Javascript route.

Twitter OAuth 1.0 215 Bad Authentication Data error when requesting token

The OAuth headers need to be sorted alphabetically. The documentation is here.

Tweepy: tweepy.error.tweeperror 'code' 215 'message' 'bad authentication data.'

I copied your code and executed it in my system and I was not able to find any errors. I'm using tweepy 3.6.0 and Python 3.5.2. There are two edits that I have done to your code.

import tweepy
ACCESS_TOKEN = "#####"
ACCESS_TOKEN_SECRET = "#####"
CONSUMER_KEY = "####"
CONSUMER_SECRET = "#####"

# OAuth process, using the keys and tokens
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
# Creation of the actual interface, using authentication
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
# collect tweets on #MRT
for tweet in tweepy.Cursor(api.search,q="MRT",count=100,
lang="en",rpp=100).items():
print (tweet.created_at, tweet.text)

Notice the two parameters tweepy.API: wait_on_rate_limit and wait_on_rate_limit_notify. These two parameters are important if you want to keep the tweets streaming on because the search API only gives you a certain amount of tweets per request.

You have a TweepError with status code 400. According to the documentation, it says:

The request was invalid or cannot be otherwise served. An accompanying error message will explain further. Requests without authentication are considered invalid and will yield this response.

A Possible explanation is that the your twitter API keys do not authenticate anymore because you have been requesting beyond the rate limits of twitter.

Hopefully this helps.



Related Topics



Leave a reply



Submit