【发布时间】:2017-04-03 22:48:34
【问题描述】:
我正在我的 Aurelia 应用程序中使用新版本的 Google Sheets API(我使用的是 TypeScript)。我已成功登录用户并询问所需的范围,但是当我尝试获取电子表格的值时,API 会引发以下错误:
cb=gapi.loaded_0:269 未捕获错误:arrayForEach 被调用时使用了一个非数组值(…)
这是我初始化 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”对象在那里,但是当我尝试从电子表格中获取数据时,它失败并出现上述错误。我正在运行的示例是针对 this 示例中使用的 Google 的公共电子表格。另请注意,我的客户端 ID 没有任何问题,因为我已经使用它运行了 Google 的示例代码并且它运行良好。
【问题讨论】:
标签: javascript typescript aurelia google-sheets-api google-api-js-client