无法在php中通过Here Map API生成令牌 [英] Cannot generate token via Here Map API in php

查看:123
本文介绍了无法在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

这篇关于无法在php中通过Here Map API生成令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆