Quandl API returns HTML 对 Google appscript 的响应

Quandl API returns HTML response on Google appscript

API 请求 quandl 获取股票数据返回 HTML 响应而不是 JSON。它正确返回 JSON 结果是 postman.

var url ='https://www.quandl.com/api/v3/datasets/BSE/BOM'+532540+'?start_date='+startDate+'&end_date='+endDate+'&collapse=weekly&api_key=myapikey'
  console.log(url)
  var options =
      {
        'muteHttpExceptions': true,
        "contentType" : "application/json",
      };
  var response = UrlFetchApp.fetch(url, options);
  console.log(response)

有人有解决方法吗?

问题:

  • Xml 响应而不是来自 quandl api
  • 的 JSON 响应

解决方案:

  • 在url中明确提到格式在documentation中提到

    GET https://www.quandl.com/api/v3/datasets/{database_code}/{dataset_code}/data.{return_format}
    
    
    var url ='https://www.quandl.com/api/v3/datasets/BSE/BOM'+532540+'.json?start_date='+startDate+'&end_date='+endDate+'&collapse=weekly&api_key=myapikey'
    

AND/OR

  • 尝试在请求中使用 Accept header 提及您只接受 json 响应。
  var options =
      {
        'muteHttpExceptions': true,
        "contentType" : "application/json",
        "headers":{"Accept":"application/json"}
      };