Reputation: 7128
I am trying to get data from here.com API and it keeps returning 401
error.
{"error":"Unauthorized","error_description":"These credentials do not authorize access"}
$minutes = 60;
$forecast = Cache::remember('forecast', $minutes, function () {
$app_id = env('HERE_APP_ID');
$app_code = env('HERE_APP_CODE');
$lat = env('HERE_LAT_DEFAULT');
$lng = env('HERE_LNG_DEFAULT');
$url = "https://weather.api.here.com/weather/1.0/report.json?product=forecast_hourly&latitude=${lat}&longitude=${lng}&oneobservation=true&language=in&app_id=${app_id}&app_code=${app_code}";
Log::info($url);
$client = new \GuzzleHttp\Client();
$res = $client->get($url);
if ($res->getStatusCode() == 200) {
$j = $res->getBody();
$obj = json_decode($j);
$forecast = $obj->hourlyForecasts->forecastLocation;
}
return $forecast;
});
Any idea?
Upvotes: 1
Views: 1363
Reputation: 28299
The correct API endpoint to use with an API Key is not https://weather.api.here.com
but https://weather.ls.hereapi.com/
.
For example:
https://weather.ls.hereapi.com/weather/1.0/report.json?apiKey=YOUR-API-KEY&product=alerts&name=Paris
Upvotes: 3