我正在尝试给出的示例 here 。具体来说,以下代码给我带来了麻烦:
<script type="text/javascript" src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>
<script type="text/javascript">
var CLIENT_ID = 'xxx...';
var SCOPES = [
'https://www.googleapis.com/auth/drive.file',
'email',
'profile',
];
function handleClientLoad() {
alert("Hi");
checkAuth();
}
我跟踪了一下,文件client.js
被我的浏览器下载了。但是,handleClientLoad()
未被调用。
示例是否完整且可运行,或者还需要什么吗?
最佳答案
是的,你说得对。加载 client.js 库时不会调用回调handleClientLoad()。我的猜测是,一旦它加载客户端库并尝试调用回调,回调(handleClientLoad())就未定义。为了使其正常工作,您应该放置第一个脚本 block <script type="text/javascript" src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>
,在第二个脚本 block 结束后。它对我有用。
尝试按照以下方式运行您的代码(经过测试并为我工作),
<script type="text/javascript">
var CLIENT_ID = 'xxx...';
var SCOPES = [
'https://www.googleapis.com/auth/drive.file',
'email',
'profile',
];
function handleClientLoad() {
alert("Hi");
checkAuth();
}
</script>
<script type="text/javascript" src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>
关于google-drive-api - Google Drive 示例中未调用 handleClientLoad 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27276794/