Andy Fiedler
Andy Fiedler

Reputation: 513

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

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 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?

Upvotes: 18

Views: 1805

Answers (2)

Eric Koleda
Eric Koleda

Reputation: 12671

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.

Upvotes: 2

ProllyGeek
ProllyGeek

Reputation: 15856

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.com/drive/web/integrate-open

Upvotes: 4

Related Questions