我正在使用PHP Curl对API进行GET调用(manheim api)。 以下是我正在使用的代码:
$vin = 'abc.............';
$atoken = 'xzc.......................';
$request_headers = array();
$request_headers[] ='Authorization: Bearer: '.$atoken;
$request_headers[] ='Content-Type: application/x-www-form-urlencoded';
$handle = curl_init();
$api_url = 'https://api.manheim.com/descriptions/capture/vin/'.$vin;
$rawPostData = array( 'grant_type' => 'client_credentials', 'client_id' => 'xzc.......................', 'client_secret' => '6sd.......' );
// $data_string = json_encode($rawPostData);
$data_string = '';
//create name value pairs seperated by &
foreach($rawPostData as $k => $v)
{
$data_string .= $k . '='.$v.'&';
}
rtrim($data_string, '&');
curl_setopt_array(
$handle,
array(
CURLOPT_URL => $api_url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $data_string,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $request_headers,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HEADER => true,
CURLOPT_TIMEOUT => -1
)
);
$data = curl_exec($handle);
echo serialize($data);
我收到以下回复:
" HTTP / 1.1 401 Unauthorized Content-Type:text / xml日期:星期五,2018年1月19日06:44:21 GMT服务器:Mashery Proxy WWW-Authenticate:Bearer realm =" api.manheim .COM" X-Error-Detail-Header:Account Inactive X-Mashery-Error-Code:ERR_403_DEVELOPER_INACTIVE X-Mashery-Responder:prod-j-worker-us-east-1e-123.mashery.com Content-Length:27 Connection:keep -活 开发人员无效
显示"开发者处于非活动状态"。我不确定我错在哪里。
答案 0 :(得分:0)
你在'Bearer'之后添加了一个冒号(:)。删除它,它应该工作。授权标头应如Authorization: Bearer myvalidtoken
当您未经过正确身份验证时,标题X-Mashery-Error-Code: ERR_403_DEVELOPER_INACTIVE
会由mashery添加。原因可能是
'授权'标头的值不正确
使用不正确的api密钥创建令牌(无法访问该端点)
您的有效令牌已过期并已从mashery数据库中删除(通常在到期后1小时)