[null,null,["上次更新時間:2025-08-31 (世界標準時間)。"],[[["\u003cp\u003eGoogle Sign-In is being deprecated; developers should consult the Deprecation and Sunset guide for more information and migration strategies.\u003c/p\u003e\n"],["\u003cp\u003eTo integrate Google Sign-In, you must create authorization credentials in the Google Developers Console and include the Google Platform Library in your web pages.\u003c/p\u003e\n"],["\u003cp\u003eYou can easily add a Google Sign-In button using a provided HTML snippet and retrieve basic user profile information after sign-in.\u003c/p\u003e\n"],["\u003cp\u003eFor server-side authentication, it is crucial to use ID tokens instead of relying on Google IDs or profile information directly.\u003c/p\u003e\n"],["\u003cp\u003eUsers can sign out of your application without signing out of Google using the provided sign-out method.\u003c/p\u003e\n"]]],[],null,["| **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|\nSupport for the Google Sign-In library is deprecated, see the [Deprecation and Sunset](/identity/sign-in/web/deprecation-and-sunset) guide for more. \n\nGoogle Sign-In manages the OAuth 2.0 flow and token lifecycle,\nsimplifying your integration with Google APIs. A user always has the option to\n[revoke access](https://myaccount.google.com/permissions) to an\napplication at any time.\n\nThis document describes how to complete a basic Google Sign-In integration.\n\nCreate authorization credentials\n\nAny application that uses OAuth 2.0 to access Google APIs must have authorization credentials\nthat identify the application to Google's OAuth 2.0 server. The following steps explain how to\ncreate credentials for your project. Your applications can then use the credentials to access APIs\nthat you have enabled for that project.\n\n1. Go to the [Clients page](https://console.developers.google.com/auth/clients).\n2. Click **Create Client**.\n3. Select the **Web application** application type.\n4. Name your OAuth 2.0 client and click **Create**\n\nAfter configuration is complete, take note of the client ID that was created.\nYou will need the client ID to complete the next steps. (A client secret is also\ncreated, but you need it only for server-side operations.)\n\nLoad the Google Platform Library\n\nYou must include the Google Platform Library on your web pages that integrate\nGoogle Sign-In. \n\n \u003cscript src=\"https://apis.google.com/js/platform.js\" async defer\u003e\u003c/script\u003e\n\nSpecify your app's client ID\n\nSpecify the client ID you created for your app in the Google Developers Console\nwith the `google-signin-client_id` meta element. \n\n```\n\u003cmeta name=\"google-signin-client_id\" content=\"YOUR_CLIENT_ID.apps.googleusercontent.com\"\u003e\n```\n| **Note:** You can also specify your app's client ID with the `client_id` parameter of the [`gapi.auth2.init()`](/identity/sign-in/web/reference#gapiauth2initparams) method.\n\nAdd a Google Sign-In button\n\nThe easiest way to add a Google Sign-In button to your site is to use an\nautomatically rendered sign-in button. With only a few lines of code, you can\nadd a button that automatically configures itself to have the appropriate text,\nlogo, and colors for the sign-in state of the user and the scopes you request.\n\nTo create a Google Sign-In button that uses the default settings, add a `div`\nelement with the class `g-signin2` to your sign-in page: \n\n \u003cdiv class=\"g-signin2\" data-onsuccess=\"onSignIn\"\u003e\u003c/div\u003e\n\nGet profile information\n\nAfter you have signed in a user with Google using the default scopes, you can\naccess the user's Google ID, name, profile URL, and email address.\n\nTo retrieve profile information for a user, use the\n[`getBasicProfile()`](/identity/sign-in/web/reference#googleusergetbasicprofile)\nmethod. \n\n function onSignIn(googleUser) {\n var profile = googleUser.getBasicProfile();\n console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.\n console.log('Name: ' + profile.getName());\n console.log('Image URL: ' + profile.getImageUrl());\n console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.\n }\n\n| **Important:** Do not use the Google IDs returned by `getId()` or the user's profile information to communicate the currently signed in user to your backend server. Instead, [send ID tokens](/identity/sign-in/web/backend-auth), which can be securely validated on the server.\n\nSign out a user\n\nYou can enable users to sign out of your app without signing out of Google by\nadding a sign-out button or link to your site. To create a sign-out link, attach\na function that calls the\n[`GoogleAuth.signOut()`](/identity/sign-in/web/reference#googleauthsignout)\nmethod to the link's `onclick` event. \n\n \u003ca href=\"#\" onclick=\"signOut();\"\u003eSign out\u003c/a\u003e\n \u003cscript\u003e\n function signOut() {\n var auth2 = gapi.auth2.getAuthInstance();\n auth2.signOut().then(function () {\n console.log('User signed out.');\n });\n }\n \u003c/script\u003e"]]