gapi is not defined - Google sign in issue with gapi.auth2.init

后端 未结 6 1510
死守一世寂寞
死守一世寂寞 2020-11-29 05:07

I\'m trying to implement Google Sign In and retrieve the profile information of the user. The error is: Uncaught ReferenceError: gapi is not defined. Why is that?



        
6条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 05:36

    The problem is not only in gapi. To call init method - auth2 object must be initialized. There is a promise once a google auth object is in fully initialized GoogleAuth.then(onInit, onFailure)

    gapi.load('auth2', initSigninV2);
    
    function initSigninV2() {
        gapi.auth2.init({
            client_id: 'CLIENT_ID.apps.googleusercontent.com'
        }).then(function (authInstance) {
            // now auth2 is fully initialized
        });
    }
    

提交回复
热议问题