0

我正在尝试使用talkdesk Reporting API。无论凭据是否正确,它都会给我 401。我正在关注此文档: https ://docs.talkdesk.com/docs/client-credentials 并且我有以下凭据:

id='XXXXXXX'
secret='XXXXXXX'
public_key='XXXXXXX'
algorithm='XXXXXXX'
private_key='XXXXXXX'
key_id ='XXXXXXX'
import requests
     
consumer_key = key_id
consumer_secret = secret
username = "XXXX"
password = "XXXXX"

payload = {
    'grant_type': 'password',
    'client_id': consumer_key,
    'client_secret': consumer_secret,
    'username': username,
    'password': password,
    'scope':'reports:read'
}
 
r = requests.post("https://xxx.talkdeskid.com/oauth/token",  headers={"Content-Type":"application/x-www-form-urlencoded"},    data=payload)
 
print(r.content)
4

1 回答 1

1

不确定是否password是 grant_type 参数的选项。该文档client_credentials仅作为一个选项提及。

下面的代码:

import requests
import base64

signed_request = base64.b64encode(b'<client_id>:<client_secret>').decode()

payload = {
    'grant_type': 'client_credentials',
    'client_id': 'xxxx',
    'client_secret': 'xxxx',
    'username': 'xxxx',
    'password': 'xxxx',
    'scope':'reports:read'
}

response = requests.post("https://xxx.talkdeskid.com/oauth/token", headers={"Authorization": "Basic {}".format(signed_request), "Content-Type":"application/x-www-form-urlencoded"}, data=payload)

print(response.content)

于 2020-12-09T20:53:57.407 回答