GData Objective-C客户端联系服务



我通过SVN下载了最后一个GData客户端https://code.google.com/p/gdata-objectivec-client/我成功地编译了它,并成功地将静态库集成到了我的项目中。

我需要检索关于谷歌用户名的所有gmail联系人:

- (GDataServiceGoogleContact *)contactService {
    static GDataServiceGoogleContact* service = nil;
    if (!service) {
        service = [[GDataServiceGoogleContact alloc] init];
        [service setShouldCacheResponseData:YES];
        [service setServiceShouldFollowNextLinks:YES];
    }
    // update the username/password each time the service is requested
    NSString *username = usr.text;
    NSString *password = psw.text;
    [service setUserCredentialsWithUsername:username
                                   password:password];
    return service;
}
- (IBAction)getContacts:(id)sender; {
    GDataServiceGoogleContact *gc =[self contactService];
    NSURL *feedURL = [GDataServiceGoogleContact contactFeedURLForUserID:usr.text];
    GDataServiceTicket *ticket;
    ticket = [gc fetchFeedWithURL:feedURL
                         delegate:self
                didFinishSelector:@selector(ticket:finishedWithFeed:error:)];
    [self startLoading];
}

回调选择器如下所示:

- (void)ticket:(GDataServiceTicket *)ticket finishedWithFeed:(GDataFeedContact *)feed
         error:(NSError *)error {
    [self stopLoading];
    if (error == nil) {
        NSArray *entries = [NSArray arrayWithArray:[feed entries]];
        if ([entries count] > 0) {
            for (GDataEntryContact *firstContact in entries) {
                NSString *name  = [((GDataNameElement*)[[firstContact name] fullName]) stringValue];
                NSString *email = ([firstContact emailAddresses] != nil && [[firstContact emailAddresses] count]!=0) ? [[[firstContact emailAddresses] objectAtIndex:0] stringValueForAttribute:@"address"]: NSLocalizedString(@"not found",@"");
                if (name == nil) {
                    name = email;
                }
                BBGmailContact *tmpContact = [[BBGmailContact alloc] initWithName:name email:email];
                [contacts addObject:tmpContact];
                [self.navigationController popViewControllerAnimated:YES];
            }
        [gmailDelegate contactsDidDownload:contacts];
        } else {
            [self createAlertView:NSLocalizedString(@"Warning", @"") message:NSLocalizedString(@"No contact found", @"")];
        }
    } else {
        [self createAlertView:NSLocalizedString(@"Error", @"Error") message:NSLocalizedString(@"Please, check your user and password", @"")];
    }
}

为什么每个条目都是一种类:GDataEntryBase而不是GDataEntryContact?我的错误在哪里?有人能帮我吗?

如果应用程序没有为联系人编译和链接到应用程序中的特定于服务的类,则条目将创建为GDataEntryBase。

也要确保按照文档中的描述指定了联系人服务的适当构建标志。

最新更新