AI-generated Key Takeaways
-
After a user signs in with Google, you can access their basic profile information such as name, profile image URL, and email address.
-
User profile information is available through the
GIDGoogleUserobject once the user has authenticated and authorized access. -
You should not use the user's profile information or
userIdto identify the signed-in user to your backend server; instead, use ID tokens.
After a user signs in with Google, you can get the user's basic profile information: their name, profile image URL, and email address.
Before you begin
- Download the dependencies and configure your Xcode project .
- Integrate Google Sign-In into your app .
Retrieving user information
Once the user has authenticated and authorized access to the scopes you request,
you can access user profile information through the GIDGoogleUser
object.
Swift
GIDSignIn
.
sharedInstance
.
signIn
(
withPresenting
:
self
)
{
signInResult
,
error
in
guard
error
==
nil
else
{
return
}
guard
let
signInResult
=
signInResult
else
{
return
}
let
user
=
signInResult
.
user
let
emailAddress
=
user
.
profile
?.
email
let
fullName
=
user
.
profile
?.
name
let
givenName
=
user
.
profile
?.
givenName
let
familyName
=
user
.
profile
?.
familyName
let
profilePicUrl
=
user
.
profile
?.
imageURL
(
withDimension
:
320
)
}
Objective-C
[
GIDSignIn
.
sharedInstance
signInWithPresentingViewController
:
self
completion
:
^
(
GIDSignInResult
*
_Nullable
signInResult
,
NSError
*
_Nullable
error
)
{
if
(
error
)
{
return
;
}
if
(
signInResult
==
nil
)
{
return
;
}
GIDGoogleUser
*
user
=
signInResult
.
user
;
NSString
*
emailAddress
=
user
.
profile
.
email
;
NSString
*
name
=
user
.
profile
.
name
;
NSString
*
givenName
=
user
.
profile
.
givenName
;
NSString
*
familyName
=
user
.
profile
.
familyName
;
NSURL
*
profilePic
=
[
user
.
profile
imageURLWithDimension
:
320
];
}];

