如何通过Access Token获取Pinterest登录用户的详细信息
Pinterest API v5 获取用户信息解决方案
你的代码核心错误是Authorization请求头格式不符合Pinterest API要求,你错误将权限标识填入了认证头,正确规则和修改方案如下:
- Pinterest v5 API使用标准OAuth2 Bearer认证格式,认证头的格式为
Bearer ${你的access_token},不需要在头中填写权限scope - 仅需要保证你之前获取access_token的授权流程中,已经向用户申请了
user_accounts:read权限即可
修正后的可运行代码如下:
const { access_token } = responseData; let userAccountDataUrl = `https://api.pinterest.com/v5/user_account`; axios.get(userAccountDataUrl, { headers: { 'Authorization': `Bearer ${access_token}` } }).then((userAccountResponse) => { const userData = userAccountResponse.data; console.log(`FetchedUserAccount=${JSON.stringify(userData, null, 2)}`); }).catch((e) => { console.log(`Error fetching user account due to ${JSON.stringify(e.response.data)}`); });
如果修改后仍然报错,可按照以下步骤排查:
- 打印
access_token确认值有效,未空或者被截断 - 确认该access_token未过期,Pinterest access_token默认有效期为30天,过期需要重新走授权流程获取
- 确认你的开发者账号后台应用已经开通了v5 API的调用权限,无调用限制
内容的提问来源于stack exchange,提问作者ololo
相关产品推荐
相关产品推荐

