[PYTHON] Get an access token for the Pocket API

Introduction

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.

1. Get the consumer key

Get the consumer key from https://getpocket.com/developer/. (Since we only proceed according to the screen here, we will omit the procedure)

2. Get request token

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)

3. Approve

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"

4. Get an access token

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

Get an access token for the Pocket API
Create a filter to get an Access Token in the Graph API (Flask)
Get an Access Token for your service account with the Firebase Admin Python SDK
Get an access token by OAuth authentication
Grant an access token with the curl command and POST the API
Access the Twitter API in Python
Google API access token and refresh token
Obtaining Azure Access Token by Python for using Microsoft Graph API
Create an alias for Route53 to CloudFront with the AWS API
Access the Docker Remote API with Requests
Try sending an email with the Gmail API Client Library for Java
Create an application using the Spotify API
Get a token for conoha in python
Get holidays with the Google Calendar API
I checked the library for using the Gracenote API
Created a Python wrapper for the Qiita API
Use the MediaWiki API to get Wiki information
Tips for hitting the ATND API in Python
[Python] Predict the appropriate rent for an apartment
Golang api get
[For beginners] Web scraping with Python "Access the URL in the page to get the contents"
[Python] Get the text of the law from the e-GOV Law API
Users without an account access the AWS Management Console
[Boto3] Search for Cognito users with the List Users API
[Fast API + Firebase] Build an API server for Bearer authentication
Get comments and subscribers with the YouTube Data API
Python: Get a list of methods for an object
An introduction to Web API development for those who have completed the Progate Go course