Refer to Getting your reading history out of Pocket using Python I got an access token to use the API (as it is). The content of the original article is --Get an access token --Get items registered in Pocket --Display the acquired items in Pandas However, here, only the contents up to the acquisition of the access token are excerpted and described.
Get the consumer key from https://getpocket.com/developer/. (Since we only proceed according to the screen here, we will omit the procedure)
Replace "your_consumer_key" in the code below with the consumer key obtained in step 1. When executed, the request token will be displayed.
import requests
from urllib.parse import urlencode
from urllib.request import Request, urlopen
codeurl = 'https://getpocket.com/v3/oauth/request' # Set destination URL here
post_fields = {"consumer_key":"your_consumer_key","redirect_uri":"http://www.google.com"} # Set POST fields here
request = Request(codeurl, urlencode(post_fields).encode())
json = urlopen(request).read().decode()
print(json)
Replace "your_request_token" in the URL below with the request token obtained in step 2, and paste it into the address bar of your browser to access it. Then, a page asking whether or not to approve will be displayed, so click "Authorize".
https://getpocket.com/auth/authorize?request_token=your_request_token&redirect_uri=http://www.google.com"
If you replace "your_consumer_key" and "your_request_token" in the code below with the ones obtained in the above procedure, the access token will be displayed.
url = 'https://getpocket.com/v3/oauth/authorize'
post_fields = {"consumer_key":"your_consumer_key","code":"your_request_token"}
request = Request(url, urlencode(post_fields).encode())
json = urlopen(request).read().decode()
print(json)
Recommended Posts