프로필 정보 가져오기

사용자가 Google로 로그인하면 사용자의 기본 프로필 정보(이름, 프로필 이미지 URL, 이메일 주소)를 가져올 수 있습니다.

시작하기 전에

사용자 정보 검색

요청한 범위에 대해 사용자가 인증하고 액세스를 승인하면 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];
}];