【发布时间】:2021-03-14 19:58:41
【问题描述】:
我正在使用这里的交通 API,它应该返回如下内容: {TIMESTAMP:“格林威治标准时间 2021 年 3 月 14 日 19:40:57”,版本:5,流量:{…}}
它大部分时间都有效,但每隔一段时间它就会返回: {TIMESTAMP:“格林威治标准时间 2021 年 3 月 14 日 19:40:57”,版本:5}
如果没有交通事故,则第二个示例将返回,但进一步刷新将返回第一个示例。代码没有任何变化;我只是刷新页面。 不管返回没有错误;我只是不知道为什么它偶尔会不准确
return fetch(`https://traffic.ls.hereapi.com/traffic/6.0/incidents.json?corridor=36.18377,-86.69355;36.08026,-86.92807;36.14638,-86.80963;36.18377,-86.69355%3B20&apiKey={API Key}`)
.then(res => {
if (res.ok) {
console.log("got a good response",res)
return res
} else {
console.log("you don't want that response")
}
})
.then(res => res.json())
.then(res => console.log("response",res))
【问题讨论】:
-
预期行为是如果没有可用的交通事件,则响应中没有 trafficitems 元素。你刷新的频率是多少?当您执行重现您报告的问题的请求时,您能否给出准确的时间戳?有一个更新的端点可用:traffic.ls.hereapi.com/traffic/6.3/incidents.json
标签: here-api here-traffic