javascript - Cannot read property 'authorize' of undefined in Google Oauth? -



javascript - Cannot read property 'authorize' of undefined in Google Oauth? -

i'm utilize oauth developing chrome extension , user can login google account.i have code jquery below.

i'm include js library in html file:

<script src="js/jquery-2.1.1.min.js" type="text/javascript"></script> <script src="js/client.js"></script>

and have js function:

function handleauthclick(event) { gapi.auth.authorize({ client_id: clientid, scope: scopes, response_type: 'code token id_token gsession', access_type: accesstype, immediate: false }, handleauthresult); homecoming false; }

my problem is: can not login google business relationship , show error : uncaught typeerror: cannot read property 'authorize' of undefined.

note: if i'm run html can login normally, can not sign in when utilize chrome extension.

it seems gapi.auth still not initialised , reason didn't follow proper chain of steps set before making call. putting here sample see if missing of steps while initializing gapi object successfully. here goes

<script type="text/javascript"> (function( gapi ) { gapi.client.setapikey(apikey); // variable apikey window.settimeout(checkauth,1); function checkauth() { gapi.auth.authorize({client_id: clientid, scope: scopes, immediate: true}, handleauthresult); } function handleauthresult(authresult) { var authorizebutton = document.getelementbyid('id-of-your-login-button'); if (authresult && !authresult.error) { authorizebutton.style.visibility = 'hidden'; makeapicall(); } else { authorizebutton.style.visibility = ''; authorizebutton.onclick = handleauthclick; } } function handleauthclick(event) { gapi.auth.authorize({ client_id: clientid, scope: scopes, response_type: 'code token id_token gsession', access_type: accesstype, immediate: false }, handleauthresult); homecoming false; } })( gapi ); </script>

you can safely set script tag in body tag below button html code.

javascript jquery google-chrome-extension oauth

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -