Popup blocking the gdrive authorization in chrome

前端 未结 5 1627
太阳男子
太阳男子 2020-12-18 09:23

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         


        
相关标签:
5条回答
  • 2020-12-18 10:00

    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 :)

    0 讨论(0)
  • 2020-12-18 10:05

    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();
    });
    
    0 讨论(0)
  • 2020-12-18 10:10

    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.

    0 讨论(0)
  • 2020-12-18 10:22

    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

    0 讨论(0)
  • 2020-12-18 10:27

    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.

    0 讨论(0)
提交回复
热议问题