0

我正在尝试获取有关天气的信息,但是当我对 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 ”中,我找不到此错误的解决方案

4

1 回答 1

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);
    }
});
于 2019-03-13T08:59:09.250 回答