0

我想为Pocket(以前读过)开发一个python客户端。

我正在研究的 OAuth 过程。并被困在这里。如何执行此请求并获得响应?

POST /v3/oauth/request HTTP/1.1
Host: getpocket.com
Content-Type: application/json; charset=UTF-8
X-Accept: application/json

{"consumer_key":"1234-abcd1234abcd1234abcd1234",
"redirect_uri":"pocketapp1234:authorizationFinished"}

我是 python 新手。这是我试过的。但我无法得到我想要的回应。

#!/usr/bin/env python

import urllib2
import json

def main():
    # Whatever structure you need to send goes here:
    jdata = json.dumps({"consumer_key":"1234-abcd1234abcd1234abcd1234", "redirect_uri":"pocketapp1234:authorizationFinished"})
    response = urllib2.urlopen("http://getpocket.com", jdata)
    the_page = response.read()
    print the_page

if __name__ == '__main__':
    main()
4

1 回答 1

3

使用该requests库进行此类工作。(已编辑)

import requests
import json


data = {"consumer_key": "..."}
headers = {"content-type": "application/json"}
response = requests.post("http://getpocket.com", data=json.dumps(data), headers=headers)
response.json
于 2012-12-13T13:42:50.510 回答