Python使用令牌(oauth2)FatSecret API请求授权标头

2024-10-02 10:22:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试连接到FatSecret API。下面是他们为oauth2授权提供的文档的链接:https://platform.fatsecret.com/api/Default.aspx?screen=rapiauth2#using-token-api

我已经完成了第一步和第二步,现在我被困在第三步。我已经设法用“application/json”更新了标题,但我不确定我的调用是否包含我创建的令牌。我收到一个响应代码200,但随后出现一条错误消息: {'error':{'code':21,'message':“检测到无效的IP地址:'51.7.45.86'”}

params = {
    'grant_type': 'client_credentials',
    'client_id': 'REMOVED',
    'client_secret': 'REMOVED',
    'scope': 'basic',
    'method' : 'foods.search',
    'search_expression' : 'toast',
    'format' : 'json',
}

api_url = 'https://platform.fatsecret.com/rest/server.api'


response = requests.post(api_url, headers={'content-type' : 'application/json', 'Authorization' : 'Bearer {}'.format(data['access_token'])}, params=params)

Error Code


Tags: httpscomclienttokenapijsonformaturl
1条回答
网友
1楼 · 发布于 2024-10-02 10:22:28
params = {
    'grant_type': 'client_credentials',
    'client_id': 'REMOVED',
    'client_secret': 'REMOVED',
    'scope': 'basic',
    'method' : 'foods.search',
    'search_expression' : 'toast',
    'format' : 'json'
}

api_url = 'https://platform.fatsecret.com/rest/server.api'


response = requests.post(api_url, headers={'Authorization' : f'Bearer {data["access_token"]}'}, json=params)

应该这样做

相关问题 更多 >

    热门问题