pocket API学习笔记

最近安装了pocket离线阅读软件。python

为了收藏须要的URL,每次都要打开浏览器。而后按google工具条上的pocket+。git

网页多的时候,这个过程就很是缓慢。github

根据pocket网站的API介绍,我能够建立一个新的应用,直接操做个人收藏夹。json

我写了一个python的脚本,你们或许能够看一下。https://github.com/febwave/python-scriptapi

1. 建立应用浏览器

首先你必需要建立一个pocket帐号。app

而后从http://getpocket.com/developer/apps/建立属于你的一个新的应用。dom

记录下CONSUMER KEY。ide

为了后续的说明,个人应用名称: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.com

request-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     }

相关文章
相关标签/搜索