問題描述
使用 Google Drive API 在 Javascript 應用程序中打開共享對話框時出現 JS 錯誤.錯誤是:未捕獲的錯誤:語法錯誤:DOM 異常 12.
I'm having a JS error when opening a share dialog in a Javascript application using the Google Drive API. The error is: Uncaught Error: Syntax Error: DOM Exception 12.
但是,當我退出所有 Google 帳戶然后只登錄一個帳戶時,共享對話框可以正常工作.當我在新標簽頁中登錄第二個帳戶后,共享對話框將不再起作用,并因上述錯誤而失敗.
However, the sharing dialog works fine when I log out of all Google accounts and then log into just one account. As soon as I log into a second account in a new tab, the sharing dialog no longer works and fails with the above error.
這與 非常相似在 Google Drive SDK 上調用 showSettingsDialog() 會引發拒絕顯示文檔,因為 X-Frame-Options 禁止顯示.但是,我已經完成了接受響應中顯示的調試,但無濟于事,即:
This is very similar to Calling showSettingsDialog() on the Google Drive SDK throws a Refused to display document because display forbidden by X-Frame-Options. However, I have done the debugging shown in the accepted response to no avail, namely:
- 您在 Google API 控制臺的 Google Drive SDK 設置中設置的打開方式"網址必須與您使用共享對話框的頁面具有相同的域.
- 目前,您還需要將您的應用程序安裝在您的 Google 云端硬盤上,以使可嵌入的小部件正常工作.我們目前正在努力消除此限制,因為自從我們推出 API v2 以來,它并不總是有意義.
相關代碼為:
var shareClient = new gapi.drive.share.ShareClient(rtpg.realTimeOptions.appId);
shareClient.setItemIds([rtclient.params['fileId']]);
shareClient.showSettingsDialog();
有沒有辦法讓登錄的多個帳戶也能正常工作?
Is there some way to make this work with multiple accounts signed in?
推薦答案
您可能需要仔細閱讀有關 x-frame 問題的內容:
you might want to read this carefully concerning the x-frame issue:
谷歌Drive API,無法通過 JS 打開標準共享對話框(x-frame-options 錯誤)
但我認為不可能一次對所有帳戶進行身份驗證,但每次您想要這樣做時,可能有一種解決方法setOAuthToken
對每個帳戶進行身份驗證.
but what i think it is not possible to authenticate all the accounts at once , but a workaround maybe to setOAuthToken
to each of them everytime you want to do so.
在 google 文檔中說明:
it is stated here in google documents that :
重要提示:setOAuthToken 函數允許應用使用當前身份驗證令牌,用于確定選擇器使用哪個 Google 帳戶顯示文件.如果用戶登錄了多個 Google 帳戶,這允許選擇器顯示適當的文件授權帳號.
Important:The setOAuthToken function allows an app to use the current auth token to determine which Google account the picker uses to display the files. If a user is signed into multiple Google accounts, this allows the picker to display the files of the appropriate authorized account.
來源:
https://developers.google.com/drive/web/integrate-open
這篇關于登錄多個帳戶時無法使 Google Drive API 共享對話框工作的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!