I'm trying to get an Access Token from Pockets API
I'm able to succesfully get a Request Token, but when I try to use that to get the Access Token, it fails with a 400 bad request error.
Here's the code:
def getAccessToken(request_code):
headers = {'Content-Type' : 'application/json; charset=UTF-8','X-Accept': 'application/json'}
request_data = json.dumps({"consumer_key":["12092-2970cc0e27ce9a25cb39f1dd"],"code":["af0f6c9b-815b-cd1d-9864-b6d375"]})
url = "https://getpocket.com/v3/oauth/authorize"
response_data = makeRequest(headers,request_data,url)
access_code, username = response_data['access_token'],response_data['username']
return access_code,username
def makeRequest(request_headers,request_data,request_url):
request = urllib2.Request(request_url,request_data,request_headers)
response = urllib2.urlopen(request)
data = json.load(response)
return data
I just can't seem to figure it out. I'm pretty sure the Request Token is valid (any way to confirm?), I go through redirecting to the Pockets authorization page, click authorize and I get redirected to the redirect_uri. On getting the redirect_uri, that's when I call getAccessToken()
If I need to provide any extra information please let me know. Thanks for any help.
Update:
Looking further into this problem, Pocket has a list of HTTPError descriptions. The one I'm throwing is 138 - Missing consumer key.
This makes even less sense now, as I'm using the exact same consumer key to obtain the request token.
Response headers:
Cache-Control: private Content-Type: text/html; charset=UTF-8 Date: Sun, 03 Mar 2013 03:54:01 GMT P3P: policyref="/w3c/p3p.xml", CP="ALL CURa ADMa DEVa OUR IND UNI COM NAV INT STA PRE" Server: Apache/2.2.23 (Amazon) Status: 400 Bad Request X-Error: Missing consumer key. X-Error-Code: 138
Remove the [
and ]
from {"consumer_key":["12092-2970cc0e27ce9a25cb39f1dd"],
. You are passing a list, where probably you should be passing a string. That should fix it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With