The following Python script should authorize me to use my Pocket app to retrieve documents. I'm running it from a Jupyter notebook.
import json
import pandas as pd
import requests
from urllib.parse import urlencode
from urllib.request import Request, urlopen
app_key = '<app key>'
request_token_url = 'https://getpocket.com/v3/oauth/request'
auth_params = {'consumer_key': app_key,
'redirect_uri': redirect_url}
oauth = requests.post(request_token_url, data=auth_params)
token = oauth.text; print(token)
<........-....-....-....-......>
auth_url = 'https://getpocket.com/v3/oauth/authorize'
redirect_uri = '<jekyll-based static blog on github>'
usr_params = {'request_token': token, 'redirect_uri': redirect_uri}
usr = requests.post(auth_url, json = usr_params)
print(usr.text)
I consistently get a status code 400 back, but am unable to detect where the error is coming from. Thanks.
First, add headers to your first POST request to get the response in JSON form:
Before your second POST request, you need to go to a web browser and manually authenticate your app. This is not something your script can handle automatically. To get the URL, you can do:
Go to this URL in your browser, authenticate your app. Then you can use the following to get an access token, which you can use in subsequent Pocket API calls:
As a final note, you can use the Pocket API python wrapper (https://github.com/tapanpandita/pocket) to simplify this entire process a bit.