我正在尝试使用Python的REST API提取销售人员报告
access_token和instance_URL为空
我尝试提供多个request.post url,但是没有用。.我给出的4个参数都正确并且正确
import requests
params = {
"grant_type": "password",
"client_id": "XXX.YYY", # Consumer Key
"client_secret": "0000000000000000", # Consumer Secret
"username": "my@email.com", # The email you use to login
"password": "MyPasswordMySecurityToken" # Concat your password and your security token
}
r = requests.post("https://test.salesforce.com/services/oauth2/token",params=params)
access_token = r.json().get("access_token")
instance_url = r.json().get("instance_url")
print("Access Token:", access_token)
print("Instance URL", instance_url)
实际:-
访问令牌:无 实例网址无
预期:-实际值
答案 0 :(得分:0)
我已经检查了您的代码,它正在使用正确的配置参数
那样修改代码并检查错误
sf_response = requests.post("https://test.salesforce.com/services/oauth2/token", params=params)
sf_response_json = sf_response.json()
if "error" in sf_response_json:
print(sf_response_json.get("error"))
print(sf_response_json.get("error_description"))
else:
access_token = sf_response_json.get("access_token")
instance_url = sf_response_json.get("instance_url")
print("Access Token:", access_token)
print("Instance URL", instance_url)
通过不正确的密码+密码成功通过
invalid_grant
身份验证失败
我得到了无效的客户ID
invalid_client_id
客户端标识符无效
对于无效的客户机密:
invalid_client
无效的客户凭据