我正在尝试按照此处的 Pinterest API 说明进行操作:https://developers.pinterest.com/docs/api/authentication/ .
我可以使用以下 URL 完成第一步,获取访问代码: https://api.pinterest.com/oauth/?response_type=code&redirect_uri=https://localhost/&client_id=XXXXXXXXXXXXX&client_secret=YYYYYYYYYYYYYYYYY&scope=read_public,write_public&state=myystatestring
这给了我代码:https://localhost/?code=ZZZZZZZZZZZZ&state=mystatestring
但是,当我尝试完成文档中的第二步“交换访问 token 的授权代码”(使用发布请求)时,我无法授权。使用此命令:
curl --data“grant_type=authorization_code&client_id=XXXXXXXXXXXXXXX&code=ZZZZZZZZZZZ”https://api.pinterest.com/v1/oauth/token
我得到:
{“status”:“失败”,“code”:3,“host”:“coreapp-devplatform-devapi-171”,“generated_at”:“2015 年 9 月 30 日星期三 16:21:26 +0000” , "message": "授权失败。", "data": null}
我也尝试过在 Python 中使用 requests 库,但结果相同。我还注意到,在第一步中,您可以将“代码”更改为“ token ”并获得包含“access_token=”的结果,但我无法交换它或直接使用它进行访问。
非常感谢任何指导!
最佳答案
实际上,我现在看到昨天已经在这个问题上提出并回答了这个问题:Auth Exception in Pinterest API
“文档是错误的。您必须在此步骤(步骤 2)而不是步骤 1 中包含您的 client_secret。因此,将“&client_secret=”添加到 postStr。 – Zack Argyle”
一旦我改变了这个,它就完美地工作了:
curl --data "grant_type=authorization_code&client_id=XXXXXXXXXXXXXXX&code=ZZZZZZZZZZZ&client_secret=YYYYYYYYYYYYYYYYY"https://api.pinterest.com/v1/oauth/token
回应:
{"access_token": "token_string_here", "token_type": "bearer", "scope": ["read_public", "write_public", "read_private", "write_private", "read_write_all"]}
谢谢扎克!
关于python - 无法使用 Pinterest API Oauth 进行授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32871162/