Đang lấy thông tin hồ sơ

Sau khi người dùng đăng nhập bằng Google, bạn có thể xem hồ sơ cơ bản của người dùng đó thông tin: tên, URL ảnh hồ sơ và địa chỉ email của họ.

Trước khi bắt đầu

Truy xuất thông tin người dùng

Sau khi người dùng xác thực và cho phép truy cập vào các phạm vi mà bạn yêu cầu, bạn có thể truy cập vào thông tin hồ sơ người dùng thông qua đối tượng GIDGoogleUser.

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)
}
[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];
}];