【问题标题】:Google drive share dialog boxGoogle 云端硬盘共享对话框
【发布时间】:2015-11-09 23:29:08
【问题描述】:

我正在使用 google drive api 在驱动程序上上传文件,它工作正常。现在我想在我的 Web 应用程序上显示共享对话框。为此,我做了以下事情:

<script type="text/javascript">

var CLIENT_ID = 'Client_ID';
  var SCOPES = [
  'https://www.googleapis.com/auth/drive',
      'email',
      'profile',
      // Add other scopes needed by your application.
    ];

  /**
   * Called when the client library is loaded.
   */
  function handleClientLoad() {

    checkAuth();
  }

  /**
   * Check if the current user has authorized the application.
   */
  function checkAuth() {
    gapi.auth.authorize(
        {'client_id': CLIENT_ID, 'scope': SCOPES, 'immediate': true,'approval_prompt':'auto'},
        handleAuthResult);
  }

  /**
   * Called when authorization server replies.
   *
   * @param {Object} authResult Authorization result.
   */
  function handleAuthResult(authResult) {

    if (authResult) {
      // Access token has been successfully retrieved, requests can be sent to the API
    } else {
      // No access token could be retrieved, force the authorization flow.
      gapi.auth.authorize(
          {'client_id': CLIENT_ID, 'scope': SCOPES, 'immediate': true},
          handleAuthResult);
    }
  }

<script>

    init = function() {
        //loadPicker();
     gapi.auth.authorize(
            {'client_id': CLIENT_ID, 'scope': SCOPES, 'immediate': true,'approval_prompt':'auto'},
            handleAuthResult);
        s = new gapi.drive.share.ShareClient(); s.setOAuthToken('tokan');
        s.showSettingsDialog();
    s.setItemIds(["<?php echo $_SESSION['file_id']; ?>"]);
    }
   // window.onload = function() {
    function load_set(){
        gapi.load('drive-share', init);

    }
</script>

现在我收到以下错误:

拒绝在框架中显示,因为它将“X-Frame-Options”设置为“SAMEORIGIN”。

据我阅读 google drive 文档,它说它需要 3 件事:

  • 用户已登录 Google
  • 用户已安装您的应用
  • 启动对话框的页面 URL 必须与为应用注册的打开 URL 具有相同的来源。

我已经使用我的 Google 帐户登录。

我不确定用户如何安装我的应用。我需要在我的页面中添加任何代码吗?

我的网址是一样的。

请清楚地描述这些要点。我在控制台中注意到的一件事是我的客户端 ID 与我上面输入的不同。就像我的客户 ID 是 [123]。

然后在控制台中显示为:

拒绝在框架中显示“https://drive.google.com/sharing/init?id=0B26e8x7MMejoZDRQZm5IOUJvbjQ&forei…nt=postMessage&appId=705048315558&embedOrigin=https%3A%2F%2FMyURL”,因为它将“X-Frame-Options”设置为“SAMEORIGIN”。

需要尽快支持。

非常感谢 高拉夫

【问题讨论】:

  • 你编辑了什么@cheryl-simon?
  • 您可以通过单击“已编辑”标签来查看。我删除了一个不正确的标签。

标签: javascript php api google-drive-api


【解决方案1】:

而不是像这样实例化共享对话框:

s = new gapi.drive.share.ShareClient('YOUR_APP_ID');

...这里有详细说明:https://developers.google.com/drive/web/manage-sharing#add_the_dialog_script

这样做:

s = 新的 gapi.drive.share.ShareClient(); s.setOAuthToken('你的 OAuth 令牌');

您的 OAuth 令牌必须具有 drive 或 drive.file 范围。在此处查看完整范围: https://developers.google.com/drive/web/scopes

【讨论】:

  • 我做到了,但仍然出现同样的错误。抱歉,我只是提到了新代码,它也是脚本的一部分。请看一下。
  • 您是否请求范围:https://www.googleapis.com/auth/drive.file?我在上面的代码中没有看到。
  • 不,请您解释一下它是什么。我是新手,这是我在网页中实现的代码。
  • 请更新您的代码示例,我可以提出建议。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多