【问题标题】:Google drive API for upload not working at all用于上传的 Google 驱动器 API 根本不起作用
【发布时间】:2015-02-24 16:48:44
【问题描述】:

我已经阅读了很多其他人的一半这个问题,并尝试了他们的解决方案,但我无能为力。

我首先在此处从 google 运行示例教程: https://campus.codeschool.com/courses/discover-drive/

然后我从这里运行示例代码: https://developers.google.com/picker/docs/index

使用我的 API 和客户端密钥运行这些代码(我什至创建了新密钥,尝试仅使用 .apps.googleusercontent.com 之前的部分作为客户端密钥,正如我在其他一些示例代码等中看到的那样.) 我得到了同样的结果。

页面加载并请求访问帐户的谷歌驱动器的权限一旦我授予它权限,它就会恢复为以下错误:

Jconsole Error

我有一个无用的窗口错误说:

出现错误! API 开发者密钥无效。

现在其他人说错误是正常的,他们的代码仍然有效。另一方面,我的不起作用,它给了我这个错误。

<script>
  var clientId = '249642562982-8ss843cvik6r1rrm94i1kt5cf4jf201c.apps.googleusercontent.com';
  var developerKey = 'AIzaSyBeDBmIqzCYCNvrpSwXcLz6ido_qGZL6sg';
  var accessToken;
  function onApiLoad() {
    gapi.load('auth', authenticateWithGoogle);
    gapi.load('picker');
  }
  function authenticateWithGoogle() {
    window.gapi.auth.authorize({
      'client_id': clientId,
      'scope': ['https://www.googleapis.com/auth/drive']
    }, handleAuthentication);
  }
  function handleAuthentication(result) {
    if(result && !result.error) {
      accessToken = result.access_token;
      setupPicker();
    }
  }
  function setupPicker() {
    var picker = new google.picker.PickerBuilder()
      .setOAuthToken(accessToken)
      .setDeveloperKey(developerKey)
      .addView(new google.picker.DocsUploadView())
      .enableFeature(google.picker.Feature.MULTISELECT_ENABLED)
      .setCallback(myCallback)
      .build();
    picker.setVisible(true);
  }
  function myCallback(data) {
    if (data.action == google.picker.Action.PICKED) {
      alert(data.docs[0].name);
    } else if (data.action == google.picker.Action.CANCEL) {
      alert('goodbye');
    }
  }
</script>
<script src="https://apis.google.com/js/api.js?onload=onApiLoad"></script>

Here are my keys

这快把我逼疯了!感觉就像我已经尝试了一切,但没有任何效果。谷歌为什么要花时间创建一个教程网站,如果翻转生成的代码不起作用,它会提供完整的视频课程来检查你的代码的有效性!?如果视频和示例代码损坏,请删除它!我在这上面浪费了一整天。

谁能帮我弄清楚这里发生了什么?

参考资料:

How to upload file on google drive from my website?

Using Google Drive in an iFrame doesn't work

Google Drive Picker - Developer Key is Invalid Error

Google Drive API OAuth 2.0; Error: origin_mismatch

【问题讨论】:

  • 我有完全相同的问题和相同的样板代码。它必须是 api 控制台中的某些设置,但我也无法弄清楚。我已授予对所有 API(云存储、驱动器、选择器等)的访问权限,并且我的密钥看起来不错。我认为这可能与 javascript 起源有关,但我已经添加了所有涉及的 URL。谜团..
  • 您解决了这个问题吗?

标签: google-drive-api picker uploader filepicker


【解决方案1】:

我建议使用this example。我也测试了这个例子,它对我有用。您可以根据自己的要求编辑范围。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-15
    • 1970-01-01
    • 1970-01-01
    • 2015-04-15
    • 1970-01-01
    • 1970-01-01
    • 2017-11-16
    • 1970-01-01
    相关资源
    最近更新 更多