[Platform] Generate the OAuth token in Python

For generating the OAuth token in Python, refer to the following code:

<br />import timeimport urllib.parseimport hmacimport hashlibfrom base64 import b64encodeimport binasciiimport requests# Credentials setupoauth_consumer_key = 'your-access-key-id' # Replace with your actual HERE access key IDaccess_key_secret = 'your-access-key-secret' # Replace with your actual HERE access key secret# OAuth parametersgrant_type = 'client_credentials'oauth_nonce = str(int(time.time()*1000))oauth_signature_method = 'HMAC-SHA256'oauth_timestamp = str(int(time.time()))oauth_version = '1.0'def create_parameter_string(**params): return '&'.join([f'{urllib.parse.quote(k, safe="")}={urllib.parse.quote(v, safe="")}' for k, v in params.items()])parameter_string = create_parameter_string( grant_type=grant_type, oauth_consumer_key=oauth_consumer_key, oauth_nonce=oauth_nonce, oauth_signature_method=oauth_signature_method, oauth_timestamp=oauth_timestamp, oauth_version=oauth_version)encoded_parameter_string = urllib.parse.quote(parameter_string, safe='')# Creating the Base Stringurl = 'https://account.api.here.com/oauth2/token'encoded_base_string = 'POST' + '&' + urllib.parse.quote(url, safe='') + '&' + encoded_parameter_string# Generating OAuth signaturesigning_key = access_key_secret + '&'def create_signature(secret_key, signature_base_string): encoded_string = signature_base_string.encode() encoded_key = secret_key.encode() hashed = hmac.new(encoded_key, encoded_string, hashlib.sha256).digest() return b64encode(hashed).decode()oauth_signature = create_signature(signing_key, encoded_base_string)encoded_oauth_signature = urllib.parse.quote(oauth_signature, safe='')# Requesting an Access Tokenheaders = { 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': f'OAuth oauth_consumer_key="{oauth_consumer_key}",oauth_nonce="{oauth_nonce}",oauth_signature="{encoded_oauth_signature}",oauth_signature_method="HMAC-SHA256",oauth_timestamp="{oauth_timestamp}",oauth_version="1.0"'}body = {'grant_type': grant_type}response = requests.post(url, data=body, headers=headers)token_data = response.json()access_token = token_data['access_token']# Using the Access Token for a HERE API request# Example: HERE Geocoding API requestgeocode_url = "https://geocode.search.hereapi.com/v1/geocode"params = {"q": "5th Avenue New York"} # Example queryauth_headers = {"Authorization": f"Bearer {access_token}"}geocode_response = requests.get(geocode_url, params=params, headers=auth_headers)print(geocode_response.json())<br />

For generating the OAuth token with a web app built by Node.js check:

Creating a Node.js Application for HERE API with OAuth 2.0 Authentication - Public KB

For using the generated OAuth token to initialize the Maps API for JavaScript, check:

JS API: OAuth Bearer Access Token Authorization instead of apikey - Public KB (here.com)