首页 > 代码库 > pocket API学习笔记
pocket API学习笔记
最近安装了pocket离线阅读软件。
为了收藏需要的URL,每次都要打开浏览器。然后按google工具条上的pocket+。
网页多的时候,这个过程就非常缓慢。
根据pocket网站的API介绍,我可以创建一个新的应用,直接操作我的收藏夹。
我写了一个python的脚本,大家或许可以看一下。https://github.com/febwave/python-script
1. 创建应用
首先你必须要创建一个pocket账号。
然后从http://getpocket.com/developer/apps/创建属于你的一个新的应用。
记录下CONSUMER KEY。
为了后续的说明,我的应用名称:pyBatchUrl。CONSUMER KEY:36822-6df058ece34310d6dceda601
2. 预备工作
阅读API说明
http://getpocket.com/developer/docs/v3/preferences-api
相信大家都能看明白的,我就不翻译了。只是需要记住使用HTTPS和post方法。
测试工具:fiddler2。
3. 获取request token
网址:https://getpocket.com/v3/oauth/request
request-header:
Content-Type: application/json; charset=UTF-8
X-Accept: application/json
Host: getpocket.comrequest-body:
{"consumer_key":"36822-6df058ece34310d6dceda601","redirect_uri":"pyBatchUrl:authorizationFinished"}
注意:pyBatchUrl是我的应用名称。
response:
{"code":"1f183197-a099-1c67-4e59-3345dc","state":null}
code就是request token。
4. 用户授权,人工执行浏览器,应该仅需要一次,成功登陆即可.如果这步不做的话,获取访问令牌将会失败。
https://getpocket.com/auth/authorize?request_token=1f183197-a099-1c67-4e59-3345dc&redirect_uri=pyBatchUrl:authorizationFinished
5. 访问令牌access token
网址:https://getpocket.com/v3/oauth/authorize
request-header
Content-Type: application/json; charset=UTF-8
X-Accept: application/json
request-body
{"consumer_key":"36822-6df058ece34310d6dceda601","code":"1f183197-a099-1c67-4e59-3345dc"}
response
{"access_token":"8f608123-0000-0000-0000-26c49e","username":baidu@sina.com}access_token就是访问令牌,后续应用程序就靠它来访问你的收藏夹了。
username 是用户注册的账号。
6. 增加新的页面
网址:https://getpocket.com/v3/add
request-header
Host: getpocket.com
Content-Type: application/json; charset=UTF-8
X-Accept: application/json
request-body:比如我想把sina加进来。
{"url":"http:\/\/www.sina.com.cn","title":"sina","consumer_key":"36822-6df058ece34310d6dceda601","access_token":"8f608123-0000-0000-0000-26c49e"}
response
{
"item": {
"item_id": "173403",
"normal_url": "http://sina.com.cn",
"resolved_id": "173403",
"extended_item_id": "173403",
"resolved_url": "http://www.sina.com.cn/",
"domain_id": "663938",
"origin_domain_id": "663938",
"response_code": "200",
"mime_type": "",
"content_length": "117286",
"encoding": "gb2312",
"date_resolved": "2014-12-13 02:58:17",
"date_published": "0000-00-00 00:00:00",
"title": "新浪首页",
"excerpt": "新浪新闻"}
"status": 1
}
}
7. 获取清单
网址:https://getpocket.com/v3/get
request-header
Host: getpocket.com
Content-Type: application/json
request-body 我就仅获取一条,count可选
{"consumer_key":"36822-6df058ece34310d6dceda601","access_token":"8f608123-0000-0000-0000-26c49e","count":"1","detailType":"simple"}
response
{
"status": 1,
"complete": 1,
"list": {
"173403": {
"item_id": "173403",
"resolved_id": "173403",
"given_url": "http://www.sina.com.cn",
"given_title": "sina",
"favorite": "0",
"status": "0",
"time_added": "1421909498",
"time_updated": "1421909498",
"time_read": "0",
"time_favorited": "0",
"sort_id": 0,
"resolved_title": "新浪首页",
"resolved_url": "http://www.sina.com.cn/",
"excerpt": "新浪新闻",
"is_article": "0",
"is_index": "1",
"has_video": "0",
"has_image": "1",
"word_count": "0"
}
},
"error": null,
"search_meta": {
"search_type": "normal"
},
"since": 1421909572
}
pocket API学习笔记