无法在php中通过Here Map API生成令牌
我已成功获取我的此处地图API签名。
现在我正在使用Here Map API来生成令牌。source link这是请求负载
POST /oauth2/token HTTP/1.1
Host: account.api.here.com
Authorization: OAuth oauth_consumer_key="1tqA_sample1fLhs2z6_q1l",oauth_signature_method="HMAC-SHA256",oauth_timestamp="1512072698",oauth_nonce="ZGAaMP",oauth_version="1.0",oauth_signature="Q0sample4lqICrx19%2F4ahaH%2Fi2O0NgqDUQJgti5U3Q%3D"
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials
我已经实现了下面的代码,但它抛出错误不匹配。授权签名或客户端凭据错误
以下是代码
$url2="https://account.api.here.com/oauth2/token";
$ch2 = curl_init();
curl_setopt($ch2,CURLOPT_URL, $url2);
//$post_add = "grant_type=client_credentials";
$post_add=array('grant_type'=> 'client_credentials');
$access_key_id ="my keys goes here";
$timer = time();
curl_setopt($ch2, CURLOPT_HTTPHEADER, array(
"Host: account.api.here.com",
"Cache-Control: no-cache",
"Authorization: OAuth oauth_consumer_key='$access_key_id',oauth_signature_method='HMAC-SHA256',oauth_timestamp='$timer',oauth_nonce='ccZGAaMP',oauth_version='1.0',oauth_signature='my signature goes here'",
'Content-Type: application/x-www-form-urlencoded'
));
curl_setopt($ch2,CURLOPT_CUSTOMREQUEST,'POST');
//curl_setopt($ch2,CURLOPT_CUSTOMREQUEST,'DELETE');
curl_setopt($ch2,CURLOPT_POSTFIELDS, $post_add);
curl_setopt($ch2,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch2,CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ch2,CURLOPT_RETURNTRANSFER, true);
$response2 = curl_exec($ch2);
curl_close($ch2);
print_r($response2);
解决方案
此问题已简单解决。我需要生成OAuth签名并将其转换为basee64,同时按照注释部分中的建议传递令牌 documentation
相关文章