2015-10-05 3 views
0

Я пытаюсь найти электронное письмо зарегистрированной учетной записи из API входа google в iOS с помощью Swift. Используемый мной код такой же, как на странице инструкции разработчиков Google.Извлечение электронной почты пользователя Google Вход iOS

Это мой код

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

Выход при печати это «описание» идентификатор это:

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

Я хочу знать, как я могу удалить излишки продукции, когда я просто хотят знать адрес электронной почты ID

Я хочу, чтобы вывод, как, например:

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

Код по запросу:

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; 
[email protected]""; } 
  • (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

ответ

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

И я хочу отметить, что ваш человек имеет ноль Bithday

+0

Как так? День рождения должен быть доступен, чтобы быть полученным правильно? В инструкциях Google говорится, что они должны. Не могли бы вы помочь мне дальше? –

+0

Я не знаю, что говорится в инструкциях Google, но в день рождения вашего кодового лица ничтожно :(Попробуйте просмотреть свой код, возможно, вы что-то не так. –

+0

О, во всяком случае .. проблема, с которой нужно бороться, - это идентификатор электронной почты извлечение –

Смежные вопросы