Alphavantage 的谷歌脚本给出了奇怪的结果 [英] Google script for Alphavantage gives weird results
问题描述
我正在尝试制作一个我想在 Google 表格中使用的 google 脚本.我在 youtube 上观看了一个教程视频,我觉得我的脚本运行良好.
但后来发生了两件奇怪的事情,我不知道为什么.
下面是我的代码,这段代码正是我想要的.它在谷歌表格和日志中显示 IBM 的 EPS.但是,当我将 APIkey 从演示"更改为对于我自己的 APIkey,它不再起作用.那时它仍然在 LOG 中显示 EPS,但我会在 Google Sheets 中得到一个空单元格.
I am trying to make a google script which i want to use in Google sheets.
I followed a tutorial video on youtube and i had the idea that my script was working well.
But then two strange things happen, and i can't figure out why.
Below is my code, this code is exactly doing what i want.
It is showing the EPS of IBM in the google sheets and also in the log.
However the moment i change the APIkey from "demo" to my own APIkey it is not working anymore.
At that moment it is still showing the EPS in the LOG, but i will get an empty cell in Google Sheets.
我不知道为什么会这样.
I have no idea why that happens.
/**
* 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 请求的任何无效证书.
Try adding {validateHttpsCertificates: false}
to your UrlFetchApp.fetch() to ignores any invalid certificates for HTTPS requests.
您的代码应如下所示:
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;
}
输出:
这篇关于Alphavantage 的谷歌脚本给出了奇怪的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!