检索用户的电子邮件Google登录iOS
我正在尝试使用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 male 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”
导入“AppDelegate.h”
@interface ViewController()
@结束
@implementation ViewController @synthesize signInButton; @synthesize signOutHandle; @synthesize signInHandle; @synthesize infoLabel; @synthesize描述; - (void)viewDidLoad {[super viewDidLoad]; signOutHandle.hidden = TRUE; }
- (void)refreshInterfaceBasedOnSignIn {if([[GPPSignIn sharedInstance] authentication]){signOutHandle.hidden = false; signInHandle.hidden = TRUE; infoLabel.text =描述; } else {
} }
(void)finishedWithAuth:(GTMOAuth2Authentication *)auth错误:(NSError *)错误{NSLog(@“Received error%@ and auth object%@”,error,auth); 如果(错误){//在这里做一些错误处理。 } 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”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]; 电子邮件=(@ “%@”,signIn.userEmail); NSLog(@“email:%@”,email); }
(void)didDisconnectWithError:(NSError *)错误{if(error){NSLog(@“Received error%@”,error); }其他{NSLog(@“用户注销并断开连接。”); //用户已注销并断开连接。 //按照Google+条款的规定清理用户数据。 }}
@结束
description = [NSString stringWithFormat: @"%@ %@ %@ %@ %@ %@ %@", person.displayName, person.gender,person.ageRange.min,person.ageRange.max,person.emails.value,person.birthday];
我想指出,你的人没有星期二
链接地址: http://www.djcxy.com/p/68097.html