我正在使用Sales Force Oauth API。我正在使用PHP
和Curl
进行API集成。当我使用Post方法访问API时,我得到了这个错误消息unsupported grant type
。
当我使用Postman使用相同的headers
和body
调用相同的API时,我得到了所需的响应。但是在我的网页上出现了一个错误。下面是代码。谢谢你的帮助
<?php
$url = 'https://mycompanynamegoeshere.my.salesforce.com/services/oauth2/token';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
$data = [
'grant_type' => 'client_credentials',
'client_id' => 'client id goes here',
'client_secret' => 'client secret goes here',
];
$data_json = json_encode($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);
curl_setopt(
$ch,
CURLOPT_HTTPHEADER,
array(
'Content-Type: application/x-www-form-urlencoded',
'Content-Length: ' . strlen($data_json),
'Cache-Control: no-cache',
'Connection: keep-alive',
'Accept: application/json',
),
);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
下面是错误消息
{"error":"unsupported_grant_type","error_description":"grant type not supported"}1
我尝试了很多在线解决方案。但没有得到任何输出。API在Postman中运行良好,并获得以下输出:
{
"access_token": "access token comes here",
"signature": "signature comes here",
"scope": "scope id comes here",
"instance_url": "my company salesforce url comes here",
"id": "my company id",
"token_type": "token comes here",
"issued_at": "issue comes here"
}
1条答案
按热度按时间fcg9iug31#