我在我的Aurelia应用程序(我正在使用TypeScript)中玩弄Google Sheets API的新版本。我已经成功地登录用户,并要求所要求的范围,但是当我试图得到一个电子表格中的API引发以下错误的值:表JavaScript API未捕获错误
cb=gapi.loaded_0:269 Uncaught Error: arrayForEach was called with a non array value(…)
这是我的初始化API和登录用户:
gapi.load("auth2",() => {
gapi.auth2.init({
'client_id': this.clientId,
'scope': this.scopes.join(' ')
}).then(() => {
this.auth = gapi.auth2.getAuthInstance();
this.auth.signIn().then(response => {
gapi.load("client",() => {
gapi.client.load("sheets", "v4",() => {
gapi.client.sheets.spreadsheets.values.get({
spreadsheetId: this.testSheet,
range: 'Class Data!A2:E'
}).then((response) => {console.log(response);});
});
});
})
});
});
的scopes
变量的作用域的数组:
scopes: string[] = ["https://www.googleapis.com/auth/spreadsheets.readonly", "https://www.googleapis.com/auth/spreadsheets", "https://www.googleapis.com/auth/drive.readonly", "https://www.googleapis.com/auth/drive"]
在用户登录成功,我甚至可以得到他们的名字和电子邮件。加载Sheets API后,我已经检查过`gapi.client'和'sheets'对象,但是当我尝试从电子表格中获取数据时,它会失败,并显示上述错误。我正在运行的示例违反了Google公开的电子表格,该示例在this示例中使用。另外请注意,我的客户端ID没有任何问题,因为我已经运行Google的示例代码,并且工作正常。
试过了..它没有工作。我直接从谷歌的例子中复制了'range'的值,但它似乎仍然没有工作... – dimlucas
是的,我现在已经尝试过这个示例,并且示例确实可以正常工作,所以这不是问题...关于你的范围的两个问题:你要求驱动器和表单的只读和完全访问,你只需要请求一个或其他(只读或不是),这取决于你是否想授予写访问权限?其次,是否启用了Drive API? – Bardy
Drive API未启用,只有Sheets API。我现在启用它,但错误仍然存在。我试着用readonly scope来运行代码。我包含了所有可用的范围,以确保错误与他们无关 – dimlucas