Pop-up blocking gdrive authorization in chrome

Thus, the problem is that the pop-up window blocks the opening of the window, even if it is performed using a user action, for example, by clicking.

gapi.auth.authorize({ client_id: this.client_id, scope: this.scopes, access_type: 'online', immediate: immediate }, function(authResult) { console.log(authResult) }); 

If I just open a window for the user, click here:

 $('.some').click(funciton(){ window.open(someurl) }) 

it works fine, but if I did this I would drop the gdrive api (gapi.auth.authorize), this is blocking anyway.

Necessarily, I cannot force users to disable popap blocking. I hope someone now how this solves :), thanks

+4
source share
5 answers

Try the following:

Include onload event in your client.js call

<script type="text/javascript" src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>

Call gapi.auth.init from the onload function:

function handleClientLoad() { window.setTimeout(gapi.auth.init,1); }

In your authorization configuration, set the immediate: false.

Verify that 1. in the page stream is below 2.

+4
source

Pop-ups that do not come from user events will be blocked depending on your browser settings. You can try setting immediate to false:

 gapi.auth.authorize({ client_id: this.client_id, scope: this.scopes, immediate: false }, function(authResult) { console.log(authResult) }); 

You can use this code to update the access token after you have already allowed the application.

+2
source

Just adding the link https://developers.google.com/api-client-library/javascript/reference/referencedocs

gapi.auth.init (callback) Initializes the authorization function. Call this when the client boots up to prevent pop-ups from blocking the auth window when gapi.auth.authorize is called.

ps: you need to vote 15 reputation .. so Ben couldn’t vote the answer :)

+1
source

The first call to the gapi.auth.authorize function may cause pop-up blockers. the best way to prevent this is to configure a user-initiated action that calls gapi.auth.authorize with an immediate: false parameter.

Quote from api documentation: https://developers.google.com/api-client-library/javascript/features/authentication#popup

0
source

You only need gapi.auth2.getAuthInstance().isSignedIn.get(); without permission authorization buttons. This will disable the popup.

 gapi.client.init({ discoveryDocs: DISCOVERY_DOCS, clientId: CLIENT_ID, scope: SCOPES }).then(function () { // Handle the initial sign-in state. gapi.auth2.getAuthInstance().isSignedIn.get(); }); 
0
source

Source: https://habr.com/ru/post/986828/


All Articles