【发布时间】:2021-01-27 06:23:06
【问题描述】:
我正在尝试从 here.com API 获取数据,但它不断返回 401 错误。
{"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;
});
有什么想法吗?
【问题讨论】:
-
试试这个网址
$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"; -
@KamleshPaul 同样的错误
-
然后转到
weatherapi仪表板并启用该服务 -
是否有单独的天气仪表板?
-
你从哪里得到那个 api 密钥? developer.here.com/documentation/destination-weather/dev_guide/…
标签: php laravel authentication here-api