Google云端硬盘共享对话框

时间:2015-08-17 10:50:15

标签: javascript php api google-drive-api

我正在使用谷歌驱动器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'。

据我阅读谷歌驱动器文档,它说它需要3件事:

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

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

我不确定用户如何安装我的应用。我需要将任何代码放入我的页面吗?

我的网址是一样的。

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

然后在控制台中显示为:

  

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

需要尽快支持。

非常感谢 拉夫

1 个答案:

答案 0 :(得分:0)

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

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

......详情请见https://developers.google.com/drive/web/manage-sharing#add_the_dialog_script

这样做:

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

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

相关问题