Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
176 views
in Technique[技术] by (71.8m points)

Cannot generate token via Here Map API in php

I have successfully obtained my hERE MAP API signature.

Now Am working with Here Map API to generate token. source link here is the request payload

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

I have implemented the code below but it throws error mismatch. Authorization signature or client credential is wrong

here is the code

$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);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This issue was simply resolved. i need to generated the oauth signature and convert it to basee64 while passing the token as suggested in the comments section and documentation


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...