Skip to content

Instantly share code, notes, and snippets.

@BERRAMOU
Last active September 21, 2019 21:28
Show Gist options
  • Save BERRAMOU/b011285dd21b12850dfd865e40c34606 to your computer and use it in GitHub Desktop.
Save BERRAMOU/b011285dd21b12850dfd865e40c34606 to your computer and use it in GitHub Desktop.
Get navToken for navionics webapi-v2 from api key.
<?php
function get_navtoken() {
// My api key.
$api_key = 'Navionics_webapi_someNumber';
$url = 'https://backend.navionics.io/tile/get_key/'.$api_key.'/webapiv2.navionics.com';
// Authorized domain by the navionics.
$referer = 'https://myhost.com';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_REFERER, $referer);
$navToken = curl_exec($ch);
// Print {"errors":[{"code":7}]}
var_dump($navToken);
$info = curl_getinfo($ch);
// Print 403.
var_dump($info['http_code']);
curl_close($ch);
if ($info['http_code'] == 200) {
return $navToken;
}else{
return '';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment