javascript - gapi.auth2.getAuthInstance() 为 null 并且 gapi.client.init 永远不会返回错误
问题描述
我正在尝试让 google API 在我的代码中工作。我使用了快速入门示例,并使其与我的 API 密钥和客户端 ID 一起使用。但是,当我将完全相同的函数及其参数移到我的代码中时:
initClient: function () {
gapi.client.init({
apiKey: this.API_KEY,
clientId: this.CLIENT_ID,
discoveryDocs: this.DISCOVERY_DOCS,
scope: this.SCOPES
}).then(function () {
// Listen for sign-in state changes.
gapi.auth2.getAuthInstance().isSignedIn.listen(this.updateSigninStatus);
// Handle the initial sign-in state.
//this.updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
//this.authorizeButton.onclick = this.handleAuthClick;
//this.signoutButton.onclick = this.handleSignoutClick;
}, function(error) {
alert(JSON.stringify(error, null, 2));
});
},
我明白了Uncaught TypeError: Cannot read property 'isSignedIn' of null
此外,无论我对 gapi.client.init 参数做什么,函数(错误)都不会触发 - 删除它们或放置不正确的键 - 它永远不会显示警报。我使用 Chrome 开发工具来确保我不会运行旧的缓存代码或其他东西。有什么问题?
解决方案
推荐阅读
- c# - 我可以有多个 ActiveItem 在主窗口中同时显示多个用户控件吗?
- flutter - Flutter 在 windows 10 上安装后无法工作
- docker - 如何删除早于 X 且未使用的 docker 映像
- php - Join Statement 不允许在外键上收集数据?
- r - 将日期从因子转换为日期,棘手的数据
- php - 用真实值交换占位符?(关于准备好的 sql 查询和执行语句)
- javascript - Websocket 服务器可以有多个 WebSocket 客户端吗?服务器:Java,客户端:C# 和 JavaScript
- javascript - 在 Angular 7 中处理大型响应式表单
- r - 为什么在函数体内发生修改时,tracemem 显示两个副本?
- mysql - 了解常规更新查询,以及一个查询可以有多少组