我正在尝试从their new GeoJSON API获取NWS提醒,但在通过Google Apps脚本提取时出现500错误。
function getAlerts() {
var rawData = UrlFetchApp.fetch('https://api.weather.gov/alerts/active', {muteHttpExceptions: true});
Logger.log(rawData);
}
日志:
{
"correlationId": "085cf198-e7ee-427c-8bb4-9bfd9f91fe9f",
"title": "Unexpected Problem",
"type": "https://api.weather.gov/problems/UnexpectedProblem",
"status": 500,
"detail": "An unexpected problem has occurred.",
"instance": "https://api.weather.gov/requests/085cf198-e7ee-427c-8bb4-9bfd9f91fe9f"
}
如果我从网络浏览器或another service转到此网址,它就可以了。救命啊!
答案 0 :(得分:1)
这是标题的问题,您可以阅读documentation(在API参考下)您应该为每个端点使用哪个标头,然后您只需添加它们:
var headers = {Accept: "application/ld+json"}
var options = {"headers": headers};
var currentWeatherUrl = "https://api.weather.gov/alerts/active?active=1"
var response = UrlFetchApp.fetch(currentWeatherUrl, options);