How to make oauth2 for here map API in php,PHP OAuth2 Here maps,How to Authenticate HERE APIs using OAuth,,oauth2 authorization code example,,here maps api tutorial,,oauth 2.0 authentication in rest api,,here map token,,get access token here map api,,get access token here map,,authenticate here map,,how to get access token here map api in php,,How to Authenticate HERE APIs using OAuth in php,,oauth2 authorization code example in php,,here maps api tutorial in php,,oauth 2.0 authentication in rest api in php,,here map token in php,,get access token here map api in php,,get access token here map in php,,authenticate here map in php,,how to get access token here map api in php,,OAuth tokens - Guide - Identity & Access Management - HERE,,Get a Token - HERE Developer
PHP

How to make oauth2 for here map API in php

How to make oauth2 for here map API in php

To make oauth2 authentication in PHP for here map you need bellow credentials:-

1) here.access.key.id

2) here.access.key.secret

Now use below code snippet to create an access token

$timer = (string) time();
$grant_type = 'client_credentials';
$oauth_consumer_key = 'here.access.key.id';
$oauth_nonce = uniqid(mt_rand(1, 1000));
$oauth_signature_method = 'HMAC-SHA256';
$oauth_timestamp = $timer;
$oauth_version = '1.0';
$url = 'https://account.api.here.com/oauth2/token';
$access_key_secret = "here.access.key.secret";

$parameter_string = 'grant_type='.$grant_type;
$parameter_string .= '&oauth_consumer_key='.$oauth_consumer_key;
$parameter_string .= '&oauth_nonce='.$oauth_nonce;
$parameter_string .= '&oauth_signature_method='.$oauth_signature_method;
$parameter_string .= '&oauth_timestamp='.$oauth_timestamp;
$parameter_string .= '&oauth_version='.$oauth_version;
$encoded_parameter_string = urlencode($parameter_string);

$encoded_base_string = 'POST'.'&'.urlencode($url).'&'.$encoded_parameter_string;

$signing_key = $access_key_secret.'&';

$signature = hash_hmac('SHA256', $encoded_base_string, $signing_key, true);

$encodedSignature = urlencode(base64_encode($signature));

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://account.api.here.com/oauth2/token',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => 'grant_type=client_credentials',
  CURLOPT_HTTPHEADER => array(
    'Authorization: OAuth oauth_consumer_key="'.$oauth_consumer_key.'",oauth_signature_method="HMAC-SHA256",oauth_timestamp="'.$oauth_timestamp.'",oauth_nonce="'.$oauth_nonce.'",oauth_version="1.0",oauth_signature="'.$encodedSignature.'"',
    'Content-Type: application/x-www-form-urlencoded'
  ),
));

$response = curl_exec($curl);
curl_close($curl);

echo $response;

Now you have a bearer access token using the above code. Use this token to use here map API’s

Post Created 130

Leave a Reply

Related Posts

Begin typing your search above and press enter to search. Press ESC to cancel.

Back To Top