2016-07-01 73 views
4

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

这是使用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是对开发商的门户网站我的注册值。

回答

3

所有对api.ua.com的调用都必须包含一个'api-key'标头值,否则您将得到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>"}'