在Google云端硬盘示例中未调用handleClientLoad函数

时间:2014-12-03 16:29:11

标签: google-drive-api

我正在尝试给出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()未被调用。

示例是否完整且可运行或是否需要其他任何内容?

1 个答案:

答案 0 :(得分:4)

是的,你是对的。回调,handleClientLoad(),在加载client.js库时没有调用。我的猜测是,只要它加载客户端库并尝试调用回调,就会定义回调(handleClientLoad())。为了使其工作,您应该在第二个脚本块结束后放置第一个脚本块<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();
  }
</script>

<script type="text/javascript" src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>