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     }

相關文章
相關標籤/搜索