Google Alphavantage 脚本给出奇怪的结果
Google script for Alphavantage gives weird results
我正在尝试制作我想在 Google 工作表中使用的 google 脚本。
我观看了 youtube 上的教程视频,我认为我的脚本运行良好。
但是后来发生了两件奇怪的事情,我不明白为什么。
下面是我的代码,这段代码正是我想要的。
它在 google 表和日志中显示了 IBM 的 EPS。
然而,当我将 APIkey 从“演示”更改为我自己的 APIkey 时,它不再起作用了。
那时它仍在日志中显示 EPS,但我会在 Google 表格中得到一个空单元格。
我不知道为什么会这样。
/**
* Imports api data from alphavantage
* @customfunction
*/
function apiav(a) {
var res = UrlFetchApp.fetch(
'https://www.alphavantage.co/query?function=OVERVIEW&symbol=IBM&apikey=demo'
);
var content = res.getContentText();
var json = JSON.parse(content);
var overviewvalue = json['EPS'];
Logger.log(overviewvalue);
return overviewvalue;
}
尝试将 {validateHttpsCertificates: false}
添加到您的 UrlFetchApp.fetch() 以忽略 HTTPS 请求的任何无效证书。
您的代码应如下所示:
function apiav(a) {
var res = UrlFetchApp.fetch('https://www.alphavantage.co/query?function=OVERVIEW&symbol=IBM&apikey=ABCDEFGH', {validateHttpsCertificates: false});
var content = res.getContentText();
var json = JSON.parse(content);
var overviewvalue = json['EPS'];
Logger.log(overviewvalue);
return overviewvalue;
}
输出:
参考:
我正在尝试制作我想在 Google 工作表中使用的 google 脚本。
我观看了 youtube 上的教程视频,我认为我的脚本运行良好。
但是后来发生了两件奇怪的事情,我不明白为什么。
下面是我的代码,这段代码正是我想要的。
它在 google 表和日志中显示了 IBM 的 EPS。
然而,当我将 APIkey 从“演示”更改为我自己的 APIkey 时,它不再起作用了。
那时它仍在日志中显示 EPS,但我会在 Google 表格中得到一个空单元格。
我不知道为什么会这样。
/**
* Imports api data from alphavantage
* @customfunction
*/
function apiav(a) {
var res = UrlFetchApp.fetch(
'https://www.alphavantage.co/query?function=OVERVIEW&symbol=IBM&apikey=demo'
);
var content = res.getContentText();
var json = JSON.parse(content);
var overviewvalue = json['EPS'];
Logger.log(overviewvalue);
return overviewvalue;
}
尝试将 {validateHttpsCertificates: false}
添加到您的 UrlFetchApp.fetch() 以忽略 HTTPS 请求的任何无效证书。
您的代码应如下所示:
function apiav(a) {
var res = UrlFetchApp.fetch('https://www.alphavantage.co/query?function=OVERVIEW&symbol=IBM&apikey=ABCDEFGH', {validateHttpsCertificates: false});
var content = res.getContentText();
var json = JSON.parse(content);
var overviewvalue = json['EPS'];
Logger.log(overviewvalue);
return overviewvalue;
}
输出: