CW:产品类型所需的城市信息:: local_conditions'此处地图

时间:2019-03-13 03:40:09

标签: node.js mongodb api express here-maps-rest

我正在尝试获取有关天气的信息,但是当我对api进行简单的后查询时,就会得到该结果

`https://weather.api.here.com/weather/1.0/report.json?app_id=${appId}&app_code=${appCode}&product=observation&name=${city}`
{ Type: 'Invalid Request',
[0]   Message:
[0]    [ 'CW: City Information Required for product type::local_conditions' ] }

在文档“ https://developer.here.com”中,我找不到此错误的解决方案

1 个答案:

答案 0 :(得分:0)

这应该非常简单,下面的代码对我有用:

const request = require('request');

const options = {
    method: 'GET',
    url: 'https://weather.api.here.com/weather/1.0/report.json',
    qs: {
        app_id: appId, // Put your APP_ID here
        app_code: appCode, // Put your APP_CODE here
        product: 'observation',
        name: 'Berlin' // Put whichever location here
    }
}

request(options, (error, response, body) => {
    if (error) {
        console.error("An error has occurred: ", error);
    } else {
        console.log("Response body: ", body);
    }
});