通过google drive sdk

时间:2015-06-23 15:00:45

标签: php google-drive-api

我正在使用php google drive sdk,并以编程方式将文档从Drive加载到div中。文档正确加载,我可以编辑和保存没有问题。当我尝试通过文档菜单使用插入图像对话框时,会出现问题,它只是加载一个空白框。

我需要做什么才能获得正确的插入图像对话框,就像我直接从驱动器中使用文档一样?下面是我用来加载文档的代码:

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 个答案:

答案 0 :(得分:0)

我认为问题在于插入图像对话框使用谷歌PickerBuilder,它使用谷歌的域作为原点,如果你看一下javascript控制台,你会看到一条消息,如

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

问题是你需要找到一种方法来告诉选择器文档的来源是什么样的特定的 Picker API。我有同样的问题,我仍然在寻找一种方法。