我正在使用 Gdata 从 Gmail 帐户中获取联系人。我能够获取用户的一些详细信息(姓名等),但是当我尝试获取电子邮件时,我收到了这个错误:
-[GDataEntryBase emailAddresses]: unrecognized selector sent to instance
从我读过的内容来看,我正在以正确的方式做这件事。我错过了什么?
代码:
-(void)getGoogleContacts {
GDataServiceGoogleContact *service =
[[GDataServiceGoogleContact alloc] init];
NSString *username = @"username@gmail.com";
NSString *password = @"pass";
service = [[GDataServiceGoogleContact alloc] init];
[service setUserAgent:@"McGraggerSoft-GoogleContactUtility-1.0"];
[service setUserCredentialsWithUsername:username password:password];
ticket = [service fetchContactFeedForUsername:username delegate:self didFinishSelector:@selector(ticket:finishedWithFeed:error:)];
}
- (void)ticket:(GDataServiceTicket *)ticket finishedWithFeed:(GDataFeedContact *)feed error:(NSError *)error
{
if ([[feed entries] count] > 0) {
GDataEntryContact *firstContact = [[feed entries] objectAtIndex:0];
GDataTextConstruct *titleTextConstruct = [firstContact title];
NSString *title = [titleTextConstruct stringValue];
NSLog(@"first contact's title:%@", title);
GDataEmail *email = [[firstContact emailAddresses] objectAtIndex:0]; //<-- Crash
//NSString *ContactEmail = [email address];
//NSLog(@"ContactEmail: %@",ContactEmail);
}
}
这是我正在使用的项目:https ://github.com/819419423/GDataWithGTMOauth2Example 您可以删除主控制器中的所有内容并添加上述方法以获取错误。