dqqlziv195281 2015-06-23 15:00
浏览 7

通过谷歌驱动器sdk加载文档时插入图像对话框

I am using the php google drive sdk, and programatically loading a document from Drive into a div. The document loads correctly and I can edit and save without issue. The problem occurs when I attempt to use the insert image dialog via the document menu, it just loads a blank white box.

What do I need to do in order to get the correct insert image dialog to load as if I was using the document directly from within drive? Below is the code I use to load the document:

function loadDocumentForView()
{
    $service = buildServiceAccountService("Google Drive account");

    $file = $service->files->get($_SESSION['selectedDocument']);
    $name = $file->getTitle();

    $ext = strtolower(substr(strrchr($name, "."), 1));

    if ($ext == 'doc' || $ext == 'docx')
    {
        if ($_SESSION['editSelectedDocument'] == 1)
        {
            $path = "https://docs.google.com/document/d/" . $_SESSION['selectedDocument'] . "/edit?usp=sharing&embedded=true";
        }
        else
        {
            $path = "https://docs.google.com/a/googleAccount/document/d/" . $_SESSION['selectedDocument'] . "/preview";
        }
    }
    else {
        echo "Incorrect Format";
        return;
    }

    $html = "";

        if ($_SESSION['editSelectedDocument'] == 1)
        {
            $html = $html . "<div style='text-align: left; margin-right: auto; margin-left: auto; margin-bottom: 15px; width:95%;'><input driveFile='" . $_SESSION['selectedDocument'] . "' type='button' value='Save' onclick='saveChangesAndDownload(this)' style='margin-right: 5px;' fileName='" . $_SESSION['selectedDocumentName'] ."'><input currentFile='" . $_SESSION['selectedDocument'] . "' type='button' value='Exit' onclick='exitWithoutSaving(this)'>";
            $html = $html . "<span id='saveFeedbackSpan' class='serverCallResult'></span></div>";
            $html = $html . "<object data='" . $path  . "' style='text-align:       center; margin-right: auto; margin-left: auto; width:95%; height: 99%;' id='documentViewerObject' doc='" . $_SESSION['selectedDocument'] . "'></object>";
        }

    echo $html;
}
  • 写回答

1条回答 默认 最新

  • dtd14883 2015-11-09 08:58
    关注

    The problem I think is that the insert image dialog uses a google PickerBuilder that uses Google's domain as the origin and if you look at the javascript console you will see a message like

    Invalid 'X-Frame-Options' header encountered when loading 'https://docs.google.com/picker?protocol=gadgets&origin=https://docs.google.…NnhLX2lIv83439cgDPmc%22%7D))&rpctoken=hyerknnixivf&rpcService=bgxw5kefbo32': 'ALLOW-FROM https://docs.google.com' is not a recognized directive. The header will be ignored.
    4080223570-picker_modularized_i18n_opc__iw.js:1008 Uncaught Error: Incorrect origin value. Please set it to - (window.location.protocol + '//' + window.location.host) of the top-most page
    

    The problem is that you need to find a way to tell the picker what the origin of the document is like specifiend in the Picker API. I have the same issue and am still looking for a way to do that as well.

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?