Getting profile information
Warning: The Google Sign-In library optionally uses FedCM APIs,
and their use will become a requirement.
Conduct an impact assessment
to confirm that user sign-in continues to function as expected.
Support for the Google Sign-In library is deprecated, see the
Deprecation and Sunset guide for more.
After you have signed in a user with Google using the default scopes, you can
access the user's Google ID, name, profile URL, and email address.
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 , which can be securely validated
on the server.
To retrieve profile information for a user, use the getBasicProfile()
method. For example:
// auth2 is initialized with gapi . auth2 . init () and a user is signed in .
if ( auth2 . isSignedIn . get ()) {
var profile = auth2 . currentUser . get () . getBasicProfile ();
console . log ( 'ID: ' + profile . getId ());
console . log ( 'Full Name: ' + profile . getName ());
console . log ( 'Given Name: ' + profile . getGivenName ());
console . log ( 'Family Name: ' + profile . getFamilyName ());
console . log ( 'Image URL: ' + profile . getImageUrl ());
console . log ( 'Email: ' + profile . getEmail ());
}
Note: A Google account's email address can change, so don't use it to identify
a user. Instead, use the account's ID, which you can get on the client with
getBasicProfile().getId()
, and on the backend from the sub
claim of the ID
token.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-10-31 UTC.
[null,null,["Last updated 2024-10-31 UTC."],[[["Google Sign-In library support is deprecated, and migration to FedCM APIs will be mandatory soon, requiring an impact assessment."],["After user sign-in, you can access basic profile information like Google ID, name, profile URL, and email address."],["Instead of Google IDs or profile data, utilize ID tokens for secure backend server authentication."],["Google account email addresses are subject to change, so use the account's ID for user identification on both client and backend."]]],[]]