0

我通过使用GData Obcective-C Client进行身份验证并从中获取联系人,将 gmail 集成到我的应用程序中。对于身份验证,我使用gtm-oauth2,这部分工作得很好。

我的GTMOAuth2ViewControllerTouch初始化范围:

NSString *scope = [NSString stringWithFormat:@"https://www.googleapis.com/auth/plus.me %@", [GDataServiceGoogleContact authorizationScope]];

授权初始化:

__keychainItemName = [infoPlist objectForKey:@"GoogleKeyChainItem"];

__auth = [GTMOAuth2ViewControllerTouch
                  authForGoogleFromKeychainForName:__keychainItemName
                  clientID:[infoPlist objectForKey:@"GoogleClientID"]
                  clientSecret:[infoPlist objectForKey:@"GoogleClientSecret"]];

对于GData构建我使用这个博客(有图片和东西)

http://hoishing.wordpress.com/2011/08/23/gdata-objective-c-client-setup-in-xcode-4/

GData我从谷歌存储库中获取,只需在控制台中运行它

# Non-members may check out a read-only working copy anonymously over HTTP.
svn checkout http://gdata-objectivec-client.googlecode.com/svn/trunk/ gdata-objectivec-client-read-only

当我尝试获取联系人时,问题就开始了:

- (GDataServiceGoogleContact *)contactService {

    static GDataServiceGoogleContact* service = nil;

    if (!service) {
        service = [[GDataServiceGoogleContact alloc] init];
        [service setShouldCacheResponseData:YES];
        [service setServiceShouldFollowNextLinks:YES];
        [service setAuthorizer:__auth];
    }

    return service;
}

- (void) methodExecute {
    GDataServiceGoogleContact *service = [self contactService];

    GDataServiceTicket *ticket;

    const int kBuncha = 2000;

    NSURL *feedURL =  [GDataServiceGoogleContact contactFeedURLForUserID:kGDataServiceDefaultUser];

    GDataQueryContact *query = [GDataQueryContact contactQueryWithFeedURL:feedURL];
    [query setShouldShowDeleted:NO];
    [query setMaxResults:kBuncha];

    [ticket setAuthorizer:__auth];

    ticket = [service fetchFeedWithQuery:query
                                delegate:self
    didFinishSelector:@selector(contactsFetchTicket:finishedWithFeed:error:)];
}

- (void)contactsFetchTicket:(GDataServiceTicket *)ticket
           finishedWithFeed:(GDataFeedContact *)feed
                      error:(NSError *)error {

    if(error != nil){
        NSLog(@"%@\n\n\n%@", error, feed);
    }
    else{
        NSLog(@"%@\n\n\n%@", error, feed.entries);
    }
}

这就是重点 - 而不是GDataEntryContact必须 in feed,我得到GDataEntryBase对象数组。有对象描述示例:

GDataEntryBase 0xb3b2300: {v:3.1 title:John Jackson etag:"Rn4_fjVSLit***." 
categories:1 links:photo,self,edit edited:2013-03-14T17:55:57Z
id:http://www.google.com/m8/feeds/contacts/myemail%40gmail.com/base/kindofid 
unparsed:<gContact:groupMembershipInfo>,<gd:name>,<gd:phoneNumber>}

我尝试将 svn 替换GDataThis GData version,但一切都没用。我在边缘。

Contacts API顺便说一句,我还在谷歌控制台上“打开”了该选项并添加-DGDATA_INCLUDE_CONTACTS_SERVICE=1Other C Flags.GData

我错过了什么还是只是愚蠢?

非常感谢您的回复!

4

1 回答 1

0

我只为项目输入了其他链接器标志,出于某种原因,它们不适用于整个目标。

于 2014-04-02T16:36:26.947 回答