Recupero delle informazioni di un profilo

Dopo che un utente esegue l'accesso con Google, puoi ottenere le informazioni di base del profilo dell'utente: il suo nome, l'URL dell'immagine del profilo e l'indirizzo email.

Prima di iniziare

Recupero dei dati utente

Dopo che l'utente ha autenticato e autorizzato l'accesso agli ambiti richiesti, puoi accedere alle informazioni del profilo utente tramite l'oggetto 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];
}];