gpt4 book ai didi

python - instapaper 和 oauth - 403 "Not logged in"错误

转载 作者:行者123 更新时间:2023-11-28 20:52:15 26 4
gpt4 key购买 nike

我正在尝试使用 instapaper API,但我的请求一直收到 403 错误。这是代码:

consumer_key='...'
consumer_secret='...'
access_token_url = 'https://www.instapaper.com/api/1/oauth/access_token'

consumer = oauth.Consumer(consumer_key, consumer_secret)
client = oauth.Client(consumer)
client.add_credentials('...','...')

params = {}
params["x_auth_username"] = '..'
params["x_auth_password"] = '...'
params["x_auth_mode"] = 'client_auth'

client.set_signature_method = oauth.SignatureMethod_HMAC_SHA1()
resp, token = client.request(access_token_url, method="POST",body=urllib.urlencode(params))
result = simplejson.load(urllib.urlopen('https://www.instapaper.com/api/1/bookmarks/list?' + token))

有什么想法吗?

最佳答案

关于签名方法,您是对的。但我的主要问题是我没有适本地处理 token 。这是工作代码:

consumer = oauth.Consumer('key', 'secret')
client = oauth.Client(consumer)

# Get access token
resp, content = client.request('https://www.instapaper.com/api/1/oauth/access_token', "POST", urllib.urlencode({
'x_auth_mode': 'client_auth',
'x_auth_username': 'uname',
'x_auth_password': 'pass'
}))

token = dict(urlparse.parse_qsl(content))
token = oauth.Token(token['oauth_token'], token['oauth_token_secret'])
http = oauth.Client(consumer, token)

# Get starred items
response, data = http.request('https://www.instapaper.com/api/1/bookmarks/list', method='POST', body=urllib.urlencode({
'folder_id': 'starred',
'limit': '100'
}))
res = simplejson.loads(data)

关于python - instapaper 和 oauth - 403 "Not logged in"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7222071/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com