用户使用 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];
}];