0

ここで説明されているように、「oauth/request_token」を呼び出して、Twitter の oauth request_token を取得しようとしています: https://dev.twitter.com/docs/auth/implementing-sign-twitter

ここでencode_params関数を使用してパラメータを生成しています: https://github.com/sixohsix/twitter/blob/master/twitter/oauth.py

次に、返された文字列をキー「Authorization」を使用して dict でラップし、Python リクエスト ライブラリを使用して作成している Post リクエストのヘッダーにダンプします。リクエストの作成に使用する 2 行を次に示します。

ep = "OAuth " + auth.encode_params(baseUrl, method, params)
response = requests.post(baseUrl+method, headers={ "Authorization" : ep})

最終的なヘッダーは次のようになります (consumer_key が変更されています)。

{'Accept': '*/*',
 'Accept-Encoding': 'gzip, deflate, compress',
 'Authorization': 'OAuth oauth_callback=http%253A%252F%252Fec2-54-244-189-248.us-west-2.compute.amazonaws.com%252Fct%252Ftwitter_login_handler%252F&oauth_consumer_key=xxx&oauth_nonce=14937468581358710045&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1366568033&oauth_version=1.0&oauth_signature=kiYucZzPY%2FXy2WyJliJ6YcggVzQ%3D',
 'Content-Length': '0',
 'User-Agent': 'python-requests/1.2.0 CPython/2.7.3 Linux/3.5.0-21-generic'}

ただし、「oauth 署名とトークンの検証に失敗しました」という 401 応答がまだ返されます。

私が間違っていることは何か分かりますか?どんな助けでも本当に感謝します。

4

3 に答える 3

0

Hopefully this helps someone else... From the code referenced by maxcountryman - it has a comment that I had not found elsewhere till then :

# Get a real consumer key & secret from https://dev.twitter.com/apps/new

That helped me progress a lot... Cheers, Ian .

于 2013-08-14T16:45:30.263 に答える
0

あなたが参照しているスクリプトについて話すことはできませんが、rauthの作成者として別のライブラリを試してみたい場合は、それをお勧めします。これは実際のTwitter の例です。それが役立つことを願っています。

于 2013-04-27T13:30:46.703 に答える