取得個人資料

使用者透過 Google 帳戶登入後,您可以取得使用者的基本個人資料 資訊:對方的名稱、個人資料圖片網址和電子郵件地址。

事前準備

擷取使用者資訊

使用者驗證並授權存取您要求的範圍後, 您可以透過 GIDGoogleUser 物件存取使用者個人資料中的資訊。

SwiftObjective-C
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];
}];