PythonでPocketのAPIを叩く方法

1. ブラウザでconsumer_keyを取得する

https://getpocket.com/developer/apps/new

2.request_tokenを取得する

import requests
payload = {'consumer_key':'12345-xxxxxxxxxxxxxxxxxxxxxxx','redirect_uri': 'http://localhost:80'}
r=requests.post('https://getpocket.com/v3/oauth/request', data=payload)
print(r.content)

3. ブラウザでアプリを認可する

https://getpocket.com/auth/authorize?request_token=xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxx&redirect_uri=http://localhost:80

4. access_tokenを取得する

payload = {'consumer_key':'12345-xxxxxxxxxxxxxxxxxxxxxxx','code': 'xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxx'}#codeはrequest_token
r=requests.post('https://getpocket.com/v3/oauth/authorize', data=payload)
print(r.content)

5.好きなAPIを叩く

payload = {'consumer_key':'12345-xxxxxxxxxxxxxxxxxxxxxxx','access_token': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxx', 'state':'all'}
r=requests.post('https://getpocket.com/v3/get',data=payload)
print(r.json())

参考その1:https://syncer.jp/pocket-api-matome

参考その2:https://getpocket.com/developer/docs/authentication