/***TheSign-Inclientobject.*/varauth2;/***InitializestheSign-Inclient.*/varinitClient=function(){gapi.load('auth2',function(){/***RetrievethesingletonfortheGoogleAuthlibraryandsetupthe*client.*/auth2=gapi.auth2.init({client_id:'CLIENT_ID.apps.googleusercontent.com'});//Attachtheclickhandlertothesign-inbuttonauth2.attachClickHandler('signin-button',{},onSuccess,onFailure);});};/***Handlesuccessfulsign-ins.*/varonSuccess=function(user){console.log('Signed in as '+user.getBasicProfile().getName());};/***Handlesign-infailures.*/varonFailure=function(error){console.log(error);};
[null,null,["最后更新时间 (UTC):2025-07-25。"],[[["\u003cp\u003eThe 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.\u003c/p\u003e\n"],["\u003cp\u003eGoogle 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.\u003c/p\u003e\n"],["\u003cp\u003eThis page provides code demonstrating how to initialize the Google Sign-In client and attach click handlers to manage user sign-in and session state.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can utilize the \u003ccode\u003eauth2\u003c/code\u003e object to handle successful and failed sign-in attempts, accessing user information upon successful authentication.\u003c/p\u003e\n"]]],[],null,["# Monitoring the user's session state\n\n| **Warning:** The Google Sign-In library optionally uses FedCM APIs, and their use will become a requirement. [Conduct an impact assessment](/identity/sign-in/web/gsi-with-fedcm) to confirm that user sign-in continues to function as expected. \n|\n| Support for the Google Sign-In library is deprecated, see the [Deprecation and Sunset](/identity/sign-in/web/deprecation-and-sunset) guide for more.\n\nAfter the Google Sign-In client has been initialized, you can attach\nhandlers that check various attributes and methods of the client to determine\nthe user's session state. You can use information returned by the client object\nto help sync your site's user experience across multiple tabs and devices for\nyour user.\n\nThe following code demonstrates using the 2.0 client method\n`attachClickHandler` to create a callback that either silently finishes sign-in\nfor the user, or prompts the user to re-authorize based on the state of the\nuser's session. \n\n /**\n * The Sign-In client object.\n */\n var auth2;\n\n /**\n * Initializes the Sign-In client.\n */\n var initClient = function() {\n gapi.load('auth2', function(){\n /**\n * Retrieve the singleton for the GoogleAuth library and set up the\n * client.\n */\n auth2 = gapi.auth2.init({\n client_id: 'CLIENT_ID.apps.googleusercontent.com'\n });\n\n // Attach the click handler to the sign-in button\n auth2.attachClickHandler('signin-button', {}, onSuccess, onFailure);\n });\n };\n\n /**\n * Handle successful sign-ins.\n */\n var onSuccess = function(user) {\n console.log('Signed in as ' + user.getBasicProfile().getName());\n };\n\n /**\n * Handle sign-in failures.\n */\n var onFailure = function(error) {\n console.log(error);\n };"]]