So, the problem is that popup blocking the window open even if it is done by a user action, click for example..
gapi.auth.authorize({
client_id: this.clie
Just adding the a reference https://developers.google.com/api-client-library/javascript/reference/referencedocs
gapi.auth.init(callback) Initializes the authorization feature. Call this when the client loads to prevent popup blockers from blocking the auth window on gapi.auth.authorize calls.
ps: vote up requires 15 reputation .. so couldn't vote up Ben's answer :)
You only needs gapi.auth2.getAuthInstance().isSignedIn.get();
without button authorize permission. This 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();
});
Try this:
Include an onload event in your call to client.js
<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 authorize configuration set immediate: false.
Check that 1. is below 2. in the flow of the page.
The first call to gapi.auth.authorize can trigger popup blockers. The best way to prevent this is to set up a user-triggered action that calls gapi.auth.authorize with immediate: false parameter.
Quoted from the api documentation: https://developers.google.com/api-client-library/javascript/features/authentication#popup
Popups that don't originate from user events will get blocked depending on your browser's 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 refresh the access token after you've already authorized the app.