最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Can't get Google Drive API share dialog to work when signed into multiple accounts - Stack Overflow

programmeradmin3浏览0评论

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.

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.

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:

  • The "open with" URL that you have setup in your Google Drive SDK settings in the Google APIs Console has to have the same domain that the page where you are using the sharing dialog.
  • Currently you alos need your application to be installed on your Google Drive for the embeddable widget to work. We are currently working on removing this restriction as it does not always make sense since we launched v2 of the API.

The relevant code is:

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?

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.

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.

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:

  • The "open with" URL that you have setup in your Google Drive SDK settings in the Google APIs Console has to have the same domain that the page where you are using the sharing dialog.
  • Currently you alos need your application to be installed on your Google Drive for the embeddable widget to work. We are currently working on removing this restriction as it does not always make sense since we launched v2 of the API.

The relevant code is:

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?

Share Improve this question edited May 23, 2017 at 12:14 CommunityBot 11 silver badge asked Mar 27, 2013 at 16:46 Andy FiedlerAndy Fiedler 5131 gold badge5 silver badges8 bronze badges 6
  • Could you check your test case against www.draw.io? It's a Google Drive app with support for sharing and multiple accounts. – Boris Jockov Commented Mar 28, 2013 at 13:54
  • @Boris I am getting the same error with draw.io. Here's how to reproduce: 1) sign into multiple google accounts. 2) go to draw.io. 3) click "Connect with Google Drive". 4) Choose one of my currently signed-in Google Accounts to connect. 5) Let draw.io connect with Drive. 6) Click File > Share. 7) Share dialog loads with an animated spinner. 8) After about 30 seconds, a message saying that "sharing is not available at this time" appears. 9) I get this in Chrome dev tools: "SyntaxError: DOM Exception 12 docs.google./static/doclist/client/js/3362885397-v2-doclist_share.js:475" – Andy Fiedler Commented Mar 31, 2013 at 20:39
  • Yeah, this looks like Google bug. Have you submitted it yet? – Boris Jockov Commented Apr 1, 2013 at 12:45
  • FWIW, there is a bug filed against this to allow passing the access token and/or user id as a hint. – Steve Bazyl Commented Apr 5, 2013 at 18:19
  • Thanks @SteveBazyl. Is the bug tracker with that bug available externally? – Andy Fiedler Commented Apr 10, 2013 at 12:45
 |  Show 1 more ment

2 Answers 2

Reset to default 4 +400

you might want to read this carefully concerning the x-frame issue:

Google Drive API, can't open standard sharing dialog via JS (x-frame-options error)

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.

it is stated here in google documents that :

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.

source:

https://developers.google./drive/web/integrate-open

We just recently added a setOAuthToken() method to the ShareClient that allows you to specify which user the dialog should use. More details in the Drive SDK release notes.

发布评论

评论列表(0)

  1. 暂无评论