Processing
 

Django and Twitter request_token

26/08/2016 13:13#1

Joined at: 4 months ago

Post: 3

Thank: 0

Thanked: 0

I am stuck with twitter signing in. By now I realized, that it is a several step thing (rather stupid in comparison with OAuth2):

  1. Make a POST request to /request_token endpoint in order to get the initial token

  2. Redirect user to /authenticate with token param from (1) in order to get another token

  3. Make another POST request to /access-token with token from (2) and finally get the desired token.

Right now I am a bit stuck with (1): twitter API always returns ERROR 215, Bad Authentication Data.

The code is like this:

    key = b"my_key&"     raw_init = "POST" + "&" + quote("https://api.twitter.com/1.1/oauth/request_token", safe='')     time_param = str(calendar.timegm(time.gmtime()))     raw_params = quote('oauth_callback', safe='') + "=" + quote('http://example.com/twitter-auth/', safe='')     raw_params += "&" + quote('oauth_consumer_key', safe='') + "=" + quote('consumer_key', safe='')     raw_params += "&" + quote('oauth_nonce', safe='') + "=" + quote('aAbBcDadadwrwwrwrwr', safe='')     raw_params += "&" + quote('oauth_signature_method', safe='') + "=" + quote('HMAC-SHA1', safe='')     raw_params += "&" + quote('oauth_timestamp', safe='') + "=" + quote(time_param, safe='')     raw_params += "&" + quote('oauth_version', safe='') + "=" + quote('1.0', safe='')     #     raw_params = quote(raw_params, safe='')     raw_final = bytes(raw_init + "&" + raw_params, encoding='utf-8')     hashed = hmac.new(key, raw_final, sha1)      request.raw_final = hashed      request.auth_header = base64.b64encode(hashed.digest()).decode() 

The code above make the signature for the Authorization header.

The POST request:

    url = 'https://api.twitter.com/1.1/oauth/request_token'     data = {}     oauth_sign_method = "HMAC-SHA1"      headers = {'Authorization': 'OAuth oauth_nonce="aAbBcDadadwrwwrwrwr"' +                                 'oauth_callback="' + quote('http://example.com/twitter-auth/', safe='') + '",' +                                 'oauth_signature_method="HMAC-SHA1",' +                                 'oauth_timestamp="' + time_param + '",'+                                 'oauth_consumer_key="consumer_key",'+                                 'oauth_signature="' + base64.b64encode(hashed.digest()).decode() + '",'+                                 'oauth_version="1.0"'}      r = requests.post(url, data=json.dumps(data), headers=headers)      answer = json.loads(r.text)      request.twitter_answer = answer 

And the answer is always with error 215 - Bad Authentication Data. Any idea why?

Similar articles

How do twitter giveaways work?

8 months ago - Reply: 2 - Views: 126

How may I get genuine followers on Twitter?

3 years ago - Reply: 33 - Views: 1,828

Login to Twitter sometime fail

6 months ago - Reply: 1 - Views: 23

Twitter doesn't accept PHP's cURL, but Linux'

1 year ago - Reply: 2 - Views: 90

Twitter OAuth on iOS

5 months ago - Reply: 1 - Views: 92

why am i getting an error on .verifyCredentials()

5 months ago - Reply: 1 - Views: 35

TwitteR setup_twitter_oauth() gives an error

5 months ago - Reply: 1 - Views: 29

Tweepy - Getting the author of a retweeted tweet

5 months ago - Reply: 0 - Views: 4

Retrieving data from twitter with JavaScript

5 months ago - Reply: 0 - Views: 2

Combined social media feed returning the wrong data

5 months ago - Reply: 0 - Views: 0

Django and Twitter request_token

5 months ago - Reply: 0 - Views: 0

Python HMAC hashed value encoding to base64

5 months ago - Reply: 1 - Views: 32

At the rate symbol in facebook

5 months ago - Reply: 0 - Views: 1

vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re