google openid - TypeError: gapi.auth2 undefined -
i went instructions integrating google sign-in:
https://developers.google.com/identity/sign-in/web/sign-in#specify_your_apps_client_id
sign-in works, sign-out gives javascript error in line:
var auth2 = gapi.auth2.getauthinstance();
the error is:
gapi.auth2 undefined
i include google platform library instructed:
<script type='text/javascript' src='https://apis.google.com/js/platform.js' async defer></script>
why not work?
are signin , signout used on same page? div g-signin2 loads , inits gapi.auth2 should work long on same page.
in case signout on separate page, should manually load , init gapi.auth2 library.
full example (you have replace your_client_id actual client_id):
<html> <head> <meta name="google-signin-client_id" content="your_client_id"> </head> <body> <script> function signout() { var auth2 = gapi.auth2.getauthinstance(); auth2.signout().then(function () { console.log('user signed out.'); }); } function onload() { gapi.load('auth2', function() { gapi.auth2.init(); }); } </script> <a href="#" onclick="signout();">sign out</a> <script src="https://apis.google.com/js/platform.js?onload=onload" async defer></script> </body> </html>