Depois que o cliente de login do Google for inicializado, você poderá anexar
gerenciadores que verificam vários atributos e métodos do cliente para determinar
o estado da sessão do usuário. Você pode usar as informações retornadas pelo objeto do cliente
para ajudar a sincronizar a experiência do usuário do seu site em várias guias e dispositivos.
O código abaixo demonstra o uso do método de cliente 2.0
attachClickHandler para criar um callback que finaliza o login
do usuário em segundo plano ou solicita que ele reautorize com base no estado da
sessão do usuário.
/** * The Sign-In client object. */ var auth2;
/** * Initializes the Sign-In client. */ var initClient =function(){ gapi.load('auth2',function(){ /** * Retrieve the singleton for the GoogleAuth library and set up the * client. */ auth2 = gapi.auth2.init({ client_id:'CLIENT_ID.apps.googleusercontent.com' });
// Attach the click handler to the sign-in button auth2.attachClickHandler('signin-button',{}, onSuccess, onFailure); }); };
/** * Handle successful sign-ins. */ var onSuccess =function(user){ console.log('Signed in as '+ user.getBasicProfile().getName()); };
[null,null,["Última atualização 2024-11-21 UTC."],[[["The Google Sign-In JavaScript library is deprecated and will eventually be sunset; developers should consult the Deprecation and Sunset guide for migration details and timelines."],["Google Sign-In will require the use of FedCM APIs in the future, so developers should conduct an impact assessment to ensure their sign-in functionality remains unaffected."],["This page provides code demonstrating how to initialize the Google Sign-In client and attach click handlers to manage user sign-in and session state."],["Developers can utilize the `auth2` object to handle successful and failed sign-in attempts, accessing user information upon successful authentication."]]],[]]