使用pinterest api的v5并停留在身份验证流上:https://developers.pinterest.com/docs/getting-started/authentication/
完成第一步并获得访问代码。但是,当我试图使用这段代码获取访问令牌时,会出现以下错误。
{"code":1,"message":"Missing request body"}
这是我的代码:
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())发布于 2022-08-09 04:37:21
下面是获取访问令牌的正确方法:
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。见阿莫斯·贝克的评论。
https://stackoverflow.com/questions/73281403
复制相似问题