首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pinterst :无法在Oauth流中获得访问令牌

Pinterst :无法在Oauth流中获得访问令牌
EN

Stack Overflow用户
提问于 2022-08-08 16:47:00
回答 1查看 154关注 0票数 0

使用pinterest api的v5并停留在身份验证流上:https://developers.pinterest.com/docs/getting-started/authentication/

完成第一步并获得访问代码。但是,当我试图使用这段代码获取访问令牌时,会出现以下错误。

{"code":1,"message":"Missing request body"}

这是我的代码:

代码语言:javascript
复制
client_id= 'my_client_id'
client_secret = 'my_client_secret'

data_string = f'{client_id}:{client_secret}'

token = base64.b64encode(data_string.encode())

headers = {
    'Authorization': 'Basic ' + token.decode('utf-8'),
    'Content-Type': 'application/x-www-form-urlencoded',
}

url = "https://api.pinterest.com/v5/oauth/token"
code = "my_code_that_i_got_in_the_first_step"

params = {
    'grant_type':'authorization_code',
    'code': code,
    'redirect_url':'https://my_redirect_uri'
}
r = requests.post(url, headers=headers, params=params)
print(r.json())
EN

回答 1

Stack Overflow用户

发布于 2022-08-09 04:37:21

下面是获取访问令牌的正确方法:

代码语言:javascript
复制
client_id= 'my_client_id'
client_secret = 'my_client_secret'

data_string = f'{client_id}:{client_secret}'

token = base64.b64encode(data_string.encode())

headers = {
    'Authorization': 'Basic ' + token.decode('utf-8'),
    'Content-Type': 'application/x-www-form-urlencoded',
}

url = "https://api.pinterest.com/v5/oauth/token"
code = "my_code_that_i_got_in_the_first_step"

data= {
    'grant_type':'authorization_code',
    'code': code,
    'redirect_uri':'https://my_redirect_uri'
}
r = requests.post(url, headers=headers, data=data)
print(r.json())

在我的问题中,我把redirect_uri误认为是redirect_url。另外,在发送帖子时,您应该使用数据而不是params。见阿莫斯·贝克的评论。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73281403

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档