問題描述
我有一個使用 Google Drive API 的 JavaScript 應(yīng)用.我在這里閱讀了如何打開標(biāo)準(zhǔn)共享對話框:https://developers.google.com/驅(qū)動器/網(wǎng)絡(luò)/管理共享
I have a JavaScript app which uses the Google Drive API. I read how to open a standard sharing dialog here: https://developers.google.com/drive/web/manage-sharing
<head>
...
<script type="text/javascript" src="https://apis.google.com/js/api.js"></script>
<script type="text/javascript">
init = function() {
s = new gapi.drive.share.ShareClient('<MY_APP_ID>');
s.setItemIds(["<MY_FILE_ID>"]);
}
window.onload = function() {
gapi.load('drive-share', init);
}
</script>
</head>
<body>
<button onclick="s.showSettingsDialog()">Share</button>
</body>
似乎我做的一切都是正確的,當(dāng)我點擊我的 share
按鈕時,對話框開始加載但無法加載.
Seems like I do everything right, when I click my share
button, the dialog starts loading but it can't be loaded.
在我看到的控制臺中:
Refused to display 'https://drive.google.com/share?...' in a frame
because it set 'X-Frame-Options' to 'SAMEORIGIN'.
我用谷歌搜索了這個錯誤,我發(fā)現(xiàn)在 SO 和其他網(wǎng)站中有一些類似的問題,但它們沒有幫助.我猜谷歌不允許自己出現(xiàn)在非谷歌網(wǎng)站的框架中(因為SAMEORIGIN").
I've googled this error and I've seen that there are some similar questions in SO and other sites, but they don't help. I guess Google doesn't allow itself to be in a frame in a not-google-site (cause of "SAMEORIGIN").
如何在我的應(yīng)用中打開共享對話框?
What can I do to open sharing dialog in my app?
推薦答案
在您的應(yīng)用中啟動 Google Drive 共享對話框"頁面 這里 聲明:
The "Launching the Google Drive sharing dialog in your app" page here states:
啟動對話框的頁面的 URL 必須具有相同的來源作為為應(yīng)用注冊的開放 URL.
The URL of the page that launches the dialog must have the same origin as the Open URL registered for the app.
如果您隨后查看配置 Drive SDK"的說明這里,您可以看到打開 URL"部分顯示為:
If you then look at the instructions to "Configure the Drive SDK" here, you can see that the "Open URL" section reads:
Open URL 有兩點需要牢記:
There are two important things to keep in mind for the Open URL:
- 確保為 Open URL 提供完全限定的域名 - localhost 不起作用.
- 該網(wǎng)址必須屬于您.應(yīng)用注冊完成后,您需要驗證您對該 URL 的所有權(quán),以便創(chuàng)建一個Chrome 網(wǎng)上應(yīng)用店列表.如需更多信息,請參閱網(wǎng)站驗證.
因此,您正在啟動對話框的頁面不與您在 Google Drive SDK 設(shè)置中為應(yīng)用注冊的打開 URL 具有相同的來源.因此,要解決您的問題,請更正 Open URL,使其具有正確的 URL,即與 Open URL 具有相同來源的 URL.請注意,您可以通過 https://console.developers.google.com/project<更改 Google Drive SDK 設(shè)置/a>.
Hence your page which is launching the dialog does not have the same origin as the Open URL registered for the app in you Google Drive SDK settings. So to fix your problem correct the Open URL so that it has the correct URL i.e. a URL with the same origin as the Open URL. Note that you can change the Google Drive SDK settings via https://console.developers.google.com/project.
以及確保正確設(shè)置打開 URL.您還需要將 Drive SDK 應(yīng)用 ID 替換為MY_APP_ID".您可以按照以下說明找到 App ID:
As well as making sure the Open URL is set correctly. You'll also need to substitute your Drive SDK app ID for 'MY_APP_ID'. You can find the App ID by following these instructions:
- 轉(zhuǎn)到 https://console.developers.google.com
- 點擊您的項目
- 點擊左側(cè)的APIs and auth"
- 點擊Drive SDK"設(shè)置齒輪圖標(biāo)
- 然后可以在Google Drive SDK"標(biāo)題下找到App ID",例如應(yīng)用 ID:47XXXXXXX3
這篇關(guān)于Google Drive API,無法通過 JS 打開標(biāo)準(zhǔn)共享對話框(x-frame-options 錯誤)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!