0

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

我需要检索有关 google 用户名的所有 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?我的错误在哪里?有人能帮我吗?

4

1 回答 1

-1

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

还要确保为联系人服务指定适当的构建标志,如文档中所述

于 2013-07-13T01:38:50.300 回答