我在后端使用Laravel / PHP与Forge系统通信。为了建立初始令牌,我使用了guzzle工具套件。效果很好。
// Get environment variables
$FusionID = getenv('THISID');
$FusionSecret = getenv('THISSECRET');
// Make call to get token with authorization code, client id, and secret
$client = new Client(); //GuzzleHttp\Client
$response = $client->request('POST', 'https://developer.api.autodesk.com/authentication/v1/gettoken', [
'form_params' => [
'grant_type' => 'authorization_code',
'code' => $authCode,
'client_id' => $FusionID,
'client_secret' => $FusionSecret,
'redirect_uri' => 'https://www.example.com/redirect',
'scope' => array('data'=>'create', 'data'=>'read')
]
]);
$body = $response->getBody();
$obj = json_decode($body);
对于许多其他命令,“ guzzle”协议似乎有问题,因此我一直在使用“ straight curl”命令。但是,我似乎都无法为刷新令牌工作。
我已经验证下面的变量具有正确的数据,但是我得到了错误
"developerMessage":"The required parameter(s) client_id,client_secret,grant_type not present in the request","userMessage":"","errorCode":"AUTH-008",
我不确定该怎么办。枪口法和卷曲法似乎都不适合我。
$thumbData = '{"client_id":"'.$FusionID.'",
"client_secret":"'.$FusionSecret.'",
"grant_type":"refresh_token",
"refresh_token":"'.$userInfo->refresh_token.'"}';
$url = 'https://developer.api.autodesk.com/authentication/v1/refreshtoken';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $thumbData );
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/x-www-form-urlencoded'
));
$response = curl_exec ($ch);
$err = curl_error($ch);
curl_close ($ch);
答案 0 :(得分:0)
使用Guzzle发布x-www-form-urlencoded
数据的方式看起来不错,所以问题就出在您的Guzzle版本是否为6+的情况下,否则请使用body
而不是form_params
作为有效负载选项。
使用cURL时,您要求的正文应以&
的格式x-www-form-urlencoded
分隔,如下所示,而不是`json:
curl_setopt($ch, CURLOPT_POSTFIELDS,
"client_id=sb233&client_secret=2333&...");