gpt4 book ai didi

python - 调用 UnderArmour api 时出现 Developer Inactive 错误

转载 作者:太空宇宙 更新时间:2023-11-03 10:58:02 24 4
gpt4 key购买 nike

尝试发布到 access_token endpoint 时收到 403“开发人员不活动”错误在 UnderArmour Connected Fitness api 中。正在使用的 client_id 处于事件状态。调用中使用的 url 是:https://api.ua.com/v7.1/oauth2/access_token/

这是获取授权码后使用python调用的片段:

import requests 
access_token_url = 'https://api.ua.com/v7.1/oauth2/access_token/'

access_token_data = {'grant_type': 'authorization_code',
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET,
'code': authorize_code}

response = requests.post(url=access_token_url, data=access_token_data)

In [24]: response
Out[24]: <Response [403]>

In [25]: response.content
Out[25]: '<h1>Developer Inactive</h1>'

其中 CLIENT_ID 和 CLIENT_SECRET 是我在开发者门户网站上注册的值。

最佳答案

对 api.ua.com 的所有调用都必须包含“api-key” header 值,否则,您将收到 403 Developer Inactive 错误。

这个片段展示了如何在 python 中做到这一点:

import requests 
access_token_url = 'https://api.ua.com/v7.1/oauth2/access_token/'

access_token_data = {'grant_type': 'authorization_code',
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET,
'code': authorize_code}

headers = {'api-key': CLIENT_ID}

response = requests.post(url=access_token_url, data=access_token_data, headers=headers)

In [30]: response
Out[30]: <Response [200]>

In [31]: response.content
Out[31]: '{"user_id": "<user_id>", "access_token": "<access token>", "expires_in": 2591999, "token_type": "Bearer", "scope": "read", "user_href": "/v7.1/user/<user id>/", "refresh_token": "<refresh token>"}'

关于python - 调用 UnderArmour api 时出现 Developer Inactive 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38151820/

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