我通过使用GData Obcective-C Client进行身份验证并从中获取联系人,将gmail集成到我的应用中。对于身份验证,我使用gtm-oauth2,这部分工作得非常好。
GTMOAuth2ViewControllerTouch
init的范围:
NSString *scope = [NSString stringWithFormat:@"https://www.googleapis.com/auth/plus.me %@", [GDataServiceGoogleContact authorizationScope]];
Auth init:
__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
我从google存储库获取,只需在控制台中运行
# 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
必须在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 GData
替换为This GData version,但一切都没用。我在边缘。
Contacts API
选项,并在-DGDATA_INCLUDE_CONTACTS_SERVICE=1
Other C Flags
添加了GData
。
我错过了什么或只是愚蠢的吗?
非常感谢您的回复!
答案 0 :(得分:0)
我只为项目输入了其他链接器标志,由于某些原因,它们不适用于整个目标。