使用者透過 Google 帳戶登入後,您可以取得使用者的基本設定檔資訊,包括使用者名稱、個人資料相片或電子郵件地址。
事前準備
擷取使用者資訊
使用者完成驗證對您要求範圍的存取權後,您就能透過 GIDGoogleUser
物件存取使用者個人資料。
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];
}];