我正在尝试使用Swift从iOS中的google登录API查找登录帐户的电子邮件。 我使用的代码与Google Developers说明页中提供的代码相同。
这是我的代码
description = [NSString stringWithFormat:@“%@%@%@%@%@%@”, person.displayName,person.gender,person.ageRange.min,person.ageRange.max,person.emails,person.birthday];
我打印此“描述”ID时的输出是:
Karanvir Singh男18 20( “GTLPlusPersonEmailsItem 0x7fbe4a67aee0:{value:\”karanvir95@gmail.com \“type:\”account \“}” )(null)
我想知道当我只想知道电子邮件ID时如何删除多余的输出
我希望输出如下:
Karanvir Singh男18 20 karanvir95@gmail.com 17/02/1995
所要求的代码:
导入“ViewController.h”
导入“GoogleOpenSource / GoogleOpenSource.h”
导入“GooglePlus / GooglePlus.h”
import“AppDelegate.h”
@interface ViewController()
@end
@implementation ViewController @synthesize signInButton; @合成 signOutHandle; @synthesize signInHandle; @synthesize infoLabel; @synthesize描述; - (void)viewDidLoad { [super viewDidLoad]; signOutHandle.hidden = TRUE; }
- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; //处理可以重新创建的任何资源。 }
- (void)refreshInterfaceBasedOnSignIn { if([[GPPSignIn sharedInstance] authentication]){ signOutHandle.hidden = FALSE; signInHandle.hidden = TRUE; infoLabel.text =描述; } else {
} }
(void)finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error { NSLog(@“收到错误%@和auth object%@”,错误,auth); if(error){ //在这里做一些错误处理 } 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(介绍); }
GTLQueryPlus * query2 = [GTLQueryPlus queryForPeopleListWithUserId:@“me” 集合: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]; 电子邮件=(@ “%@”,signIn.userEmail); NSLog(@“email:%@”,电子邮件); }
(void)didDisconnectWithError:(NSError *)error { if(error){ NSLog(@“收到错误%@”,错误); } else { NSLog(@“用户已注销并断开连接。”); //用户已注销并已断开连接。 //清理Google+条款指定的用户数据。 }
@end
答案 0 :(得分:0)
description = [NSString stringWithFormat: @"%@ %@ %@ %@ %@ %@ %@", person.displayName, person.gender,person.ageRange.min,person.ageRange.max,person.emails.value,person.birthday];
我想要注意你的人没有生日