我不知道这是正确的方法,但请听我这样做,并始终得到像'Failed to validate oauth signature and token'
def twitterapi(request):
consumer = oauth.Consumer(settings.TWITTER_TOKEN, settings.TWITTER_SECRET)
client = oauth.Client(consumer)
resp, content = client.request(request_token_url, "GET")
pprint.pprint(resp)
pprint.pprint(content)
结果是
System check identified no issues (0 silenced).
January 03, 2015 - 08:45:10
Django version 1.7, using settings 'panaface.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
{'-content-encoding': 'gzip',
'cache-control': 'no-cache, no-store, must-revalidate, pre-check=0, post-check=0',
'content-length': '44',
'content-security-policy': "default-src https:; connect-src https:; font-src https: data:; frame-src https:; img-src https: data:; media-src https:; object-src https:; script-src 'unsafe-inline' 'unsafe-eval' https:; style-src 'unsafe-inline' https:; report-uri https://twitter.com/i/csp_report?a=NVXW433SMFUWY%3D%3D%3D&ro=false;",
'content-type': 'text/html; charset=utf-8',
'date': 'Sat, 03 Jan 2015 08:47:24 UTC',
'expires': 'Tue, 31 Mar 1981 05:00:00 GMT',
'last-modified': 'Sat, 03 Jan 2015 08:47:24 GMT',
'pragma': 'no-cache',
'server': 'tsa_a',
'set-cookie': '_twitter_sess=BAh7CDoHaWQiJTcwYTAxMzVhMTM0YzhlNDgwNmI1NjRmODJjZjFlMmYxIgpm%250AbGFzaElDOidBY3Rpb25Db250cm9sbGVyOjpGbGFzaDo6Rmxhc2hIYXNoewAG%250AOgpAdXNlZHsAOg9jcmVhdGVkX2F0bCsISkP6rkoB--6978073a14c7d735bf7ed13a80b2eafc0e5dc46f; domain=.twitter.com; path=/; secure; HttpOnly, guest_id=v1%3A142027484448220098; Domain=.twitter.com; Path=/; Expires=Mon, 02-Jan-2017 08:47:24 UTC',
'status': '401',
'strict-transport-security': 'max-age=631138519',
'vary': 'Accept-Encoding',
'x-connection-hash': '26631716b8f2ff3b102e3a7c22d91721',
'x-content-type-options': 'nosniff',
'x-frame-options': 'SAMEORIGIN',
'x-mid': 'c563cdb124cbb8519fc1a427d5bca474fb935835',
'x-response-time': '198',
'x-runtime': '0.01023',
'x-transaction': '5fcfba75ba1c82b0',
'x-ua-compatible': 'IE=edge,chrome=1',
'x-xss-protection': '1; mode=block'}
'Failed to validate oauth signature and token'
[03/Jan/2015 08:47:24]
答案 0 :(得分:0)
您收到错误是因为request_token url不正确。它是......
request_token_url = 'http://api.twitter.com/oauth/request_token'
access_token_url = 'http://api.twitter.com/oauth/access_token'
# This is the slightly different URL used to authenticate/authorize.
authenticate_url = 'http://api.twitter.com/oauth/authenticate'