0
votes

I am trying to find the email of the logged in account from the google login API in iOS using Swift. The code i used is the same as given in the google Developers instruction page.

This is my code

description = [NSString stringWithFormat: @"%@ %@ %@ %@ %@ %@", person.displayName,person.gender,person.ageRange.min,person.ageRange.max,person.emails,person.birthday];

The output when i print this "description" id is this:

Karanvir Singh male 18 20 ( "GTLPlusPersonEmailsItem 0x7fbe4a67aee0: {value:\"[email protected]\" type:\"account\"}" ) (null)

I want to know how i can remove the excess of output when i just want to know the email ID

i want the output as such:

Karanvir Singh male 18 20 [email protected] 17/02/1995

Code as requested:

import "ViewController.h"

import "GoogleOpenSource/GoogleOpenSource.h"

import "GooglePlus/GooglePlus.h"

import "AppDelegate.h"

@interface ViewController ()

@end

@implementation ViewController @synthesize signInButton; @synthesize signOutHandle; @synthesize signInHandle; @synthesize infoLabel; @synthesize description; - (void)viewDidLoad { [super viewDidLoad]; signOutHandle.hidden=true; }

  • (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }

-(void)refreshInterfaceBasedOnSignIn { if ([[GPPSignIn sharedInstance] authentication]) { signOutHandle.hidden=false; signInHandle.hidden=true; infoLabel.text=description; } else {

} }
  • (void)finishedWithAuth: (GTMOAuth2Authentication *)auth error: (NSError *) error { NSLog(@"Received error %@ and auth object %@",error, auth); if (error) { // Do some error handling here. } else {

    GTLServicePlus* plusService = [[GTLServicePlus alloc] init];
    plusService.retryEnabled = YES;
    [plusService setAuthorizer:[GPPSignIn sharedInstance].authentication];
    
    GTLQueryPlus *query = [GTLQueryPlus queryForPeopleGetWithUserId:@"me"];
    query.collection=kGTLPlusCollectionVisible;
    [plusService executeQuery:query
            completionHandler:^(GTLServiceTicket *ticket,
                                GTLPlusPerson *person,
                                NSError *error){
                if (error) {
                    GTMLoggerError(@"Error: %@", error);
                } else {
                //    [person retain];
                    NSString *age = [NSString string];
                    description = [NSString stringWithFormat: @"%@ %@ %@ %@ %@ %@ %@", person.displayName,person.gender,person.ageRange.min,person.ageRange.max,person.emails,person.birthday,email];
    

NSLog(description); }

GTLQueryPlus *query2 = [GTLQueryPlus queryForPeopleListWithUserId:@"me" collection:kGTLPlusCollectionVisible];

[plusService executeQuery:query2 completionHandler:^(GTLServiceTicket *ticket, GTLPlusPeopleFeed *peopleFeed, NSError *error) {

                            if (error) {

                                GTMLoggerError(@"Error: %@", error);

                            } else {
                                // Get an array of people from GTLPlusPeopleFeed

NSArray* peopleList = peopleFeed.items;

                            }
                        }];
                [self refreshInterfaceBasedOnSignIn];
            }];
} }

- (IBAction)signOutButton:(id)sender { [[GPPSignIn sharedInstance] signOut]; [[GPPSignIn sharedInstance] disconnect];

signOutHandle.hidden=true;
signInHandle.hidden=false;
infoLabel.text=@""; }
  • (void)signOut { [[GPPSignIn sharedInstance] signOut]; }

  • (void)disconnect { [[GPPSignIn sharedInstance] disconnect]; }

  • (IBAction)signedIn:(id)sender { GPPSignIn *signIn = [GPPSignIn sharedInstance]; signIn.shouldFetchGooglePlusUser = YES; signIn.shouldFetchGoogleUserEmail = YES; signIn.clientID = kClientId;

    AppDelegate *appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];

    signIn.shouldFetchGoogleUserEmail = YES; signIn.delegate = self;

    signIn.scopes = @[ kGTLAuthScopePlusUserinfoProfile, kGTLAuthScopePlusLogin,kGTLAuthScopePlusMe,kGTLAuthScopePlusUserinfoEmail ]; signIn.delegate = self; [signIn authenticate]; email=(@"%@",signIn.userEmail); NSLog(@" email:%@",email); }

  • (void)didDisconnectWithError:(NSError *)error { if (error) { NSLog(@"Received error %@", error); } else { NSLog(@"The user is signed out and disconnected."); // The user is signed out and disconnected. // Clean up user data as specified by the Google+ terms. } }

@end

1

1 Answers

0
votes
description = [NSString stringWithFormat: @"%@ %@ %@ %@ %@ %@ %@", person.displayName, person.gender,person.ageRange.min,person.ageRange.max,person.emails.value,person.birthday];

And I want to note that your person has nil bithday