Setelah pengguna login dengan Google, Anda dapat memperoleh profil dasar pengguna informasi: nama, URL gambar profil, dan alamat email mereka.
Sebelum memulai
- Download dependensi dan konfigurasi project Xcode Anda.
- Mengintegrasikan Login dengan Google ke dalam aplikasi.
Mengambil informasi pengguna
Setelah pengguna mengotentikasi dan
mengotorisasi akses ke cakupan yang Anda minta,
Anda dapat mengakses informasi profil pengguna melalui objek 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];
}];