表格JavaScript API未捕获错误 [英] Sheets JavaScript API Uncaught Error

查看:80
本文介绍了表格JavaScript API未捕获错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Aurelia应用程序中使用新版本的Google表格API(我正在使用TypeScript)。我设法登录用户并询问所需的范围但是当我试图获取电子表格的值时,API会引发以下错误:

I'm playing around with the new version of the Google Sheets API in my Aurelia application (I'm using TypeScript). I've managed to login the user and ask for the required scopes but when I'm trying to get the values of a spreadsheet the API throws the following error:


cb = gapi.loaded_0:269未捕获错误:使用非数组值调用arrayForEach(...)

cb=gapi.loaded_0:269 Uncaught Error: arrayForEach was called with a non array value(…)

这是我初始化API并登录用户的方式:

This is how I initialize the API and login the user:

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: 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'并且'sheet'对象在那里,但是当我尝试从电子表格中获取数据时,它会因上述错误而失败。我正在运行的示例是针对用于示例的Google公开电子表格。另请注意,我的客户端ID没有任何问题,因为我使用它运行Google的示例代码并且工作正常。

The user logs in successfully, I can even get their name and email. After loading the Sheets API I've checked `gapi.client' and the 'sheets' object is there but when I try to get data from a spreadsheet it fails with the above error. The example I'm running is against Google's public spreadsheet that is used in this example. Also note that there is nothing wrong with my client id as I've run Google's sample code with it and it works fine.

推荐答案

您的工作表是否命名为 Class Data ?,如果是这样,可能需要按如下方式指定范围:

Is your Sheet named Class Data?, if so, it might be necessary to specify the range as follows:

range: "'Class Data'!A2:E"

这当然是正确的Sheets UI和Apps Scripts,我试图记住我是否对JS客户端库有相同的想法。

This is certainly true within the Sheets UI and Apps Scripts, and I'm trying to remember if I experienced the same with the JS client library.

这篇关于表格JavaScript API未捕获错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆