gpt4 book ai didi

javascript - 刷新比。重新加载(无法调用未定义的方法 'authorize')GAPI

转载 作者:行者123 更新时间:2023-11-28 01:46:06 25 4
gpt4 key购买 nike

我有一个简单的 gapi (Google Drive) 应用程序,我想连接到它。发生了一些奇怪的事情。我有演示中的示例。 https://developers.google.com/drive/web/quickstart/quickstart-js

//Nothing happens
<script src="static/javascript/libs/client.js?onload=Drive._handleClientLoad"></script>

//Works on reload but not refresh
// (reload) "successfully authorization"
// (refresh) "Uncaught TypeError: Cannot call method 'authorize' of undefined"
<script src="static/javascript/libs/client.js" onload="Drive._handleClientLoad"></script>

Javascript:


var Drive = {

_CLIENT_ID: '61183508825.apps.googleusercontent.com',
_SCOPES: 'https://www.googleapis.com/auth/drive.file',
_rootid: null,
authorised: false,

_auth: function() {
gapi.auth.authorize({
'client_id': Drive._CLIENT_ID, 'scope': Drive._SCOPES, 'immediate': true
},Drive._handleAuthResult);
},

_handleClientLoad: function() {
window.setTimeout(Drive._auth, 1);
},

_handleAuthResult: function(authResult) {
if (authResult && !authResult.error) {
// Access token has been successfully retrieved, requests can be sent to the API.
Drive._validAuth();
} else {
// No access token could be retrieved, show the button to start the authorization flow.
Drive._invalidAuth();
}
},

_invalidAuth: function(){
Drive.authorised = false;
console.log("invalid authorization");
},

_validAuth: function(){
Drive.authorised = true;
console.log("successfully authorization");
},

}

为什么会这样?

最佳答案

html 应该与您的第一个代码段一致。你需要弄清楚为什么“什么都没有发生”。可能是 Google 库中的某些限制阻止它调用模块。尝试将 Drive._handleClientLoad 替换为全局函数,该函数又会调用您的模块。或许在其中加入一些控制台日志或调试器,以查看正在执行的内容和未执行的内容。

关于javascript - 刷新比。重新加载(无法调用未定义的方法 'authorize')GAPI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22568329/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com