내 iPhone 응용 프로그램에서 Gmail & yahoo 연락처를 가져 오려고합니다.iOS의 gmail 계정에서만 MyContacts 가져 오기
Gmail의 경우 GTMOauth2.0을 사용했습니다. MyContacts 그룹의 연락처 만 필요할 때 모든 연락처를 볼 수 있습니다. 나는 연락처를 얻으려면 다음 코드를 사용한 다음 API에서
-(void)signInToGoogle:(id)sender
{
[self signOutFromGoogle];
NSString *keychainItemName = nil;
NSString *scope = @"https://www.google.com/m8/feeds/contacts/default/full";
NSString *clientID = @"CLIENTID";
NSString *clientSecret = @"CLIENTSECRETID";
SEL finishedSel = @selector(viewController:finishedWithAuth:error:);
GTMOAuth2ViewControllerTouch *viewController;
viewController = [GTMOAuth2ViewControllerTouch controllerWithScope:scope
clientID:clientID
clientSecret:clientSecret
keychainItemName:keychainItemName
delegate:self
finishedSelector:finishedSel];
NSDictionary *params = [NSDictionary dictionaryWithObject:@"en" forKey:@"hl"];
viewController.signIn.additionalAuthorizationParameters = params;
NSString *html = @"<html><body bgcolor=silver><div align=center>Loading sign-in page...</div></body></html>";
viewController.initialHTMLString = html;
[[self navigationController] pushViewController:viewController animated:YES];
}
- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController
finishedWithAuth:(GTMOAuth2Authentication *)auth
error:(NSError *)error {
[[NSNotificationCenter defaultCenter] removeObserver:self];
if (error != nil) {
[processObj removeFromSuperview];
self.view.userInteractionEnabled = YES;
NSLog(@"Authentication error: %@", error);
NSData *responseData = [[error userInfo] objectForKey:@"data"]; // kGTMHTTPFetcherStatusDataKey
if ([responseData length] > 0) {
// show the body of the server's authentication failure response
NSString *str = [[NSString alloc] initWithData:responseData
encoding:NSUTF8StringEncoding];
NSLog(@"%@", str);
}
self.auth = nil;
} else {
self.auth = auth;
[self doAnAuthenticatedAPIFetch];
}
}
- (void)doAnAuthenticatedAPIFetch {
NSString *urlStr = @"https://www.google.com/m8/feeds/groups/default/full/Contacts";
NSURL *url = [NSURL URLWithString:urlStr];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[self.auth authorizeRequest:request
completionHandler:^(NSError *error) {
NSString *output = nil;
if (error) {
output = [error description];
} else {
NSURLResponse *response = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
if (data) {
// API fetch succeeded :Here I am getti
output = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
} else {
// fetch failed
output = [error description];
}
}
}];
}
가 나는 그룹 ID로 "연락처"를 통과하고 있지만 "그룹 ID를 찾을 수 없음"오류를 반환합니다. 나는 https://developers.google.com/google-apps/contacts/v3/?csw=1
에서 Google 문서를 가지고 있지만 여전히 문제를 해결할 수 없습니다. 이것들을 도와주세요.
나는 Gmail과 접촉하려고하지만 동일한 해결책을 얻지 못했습니다. 당신이 ans를 얻는다면, 어떻게 그것이 가능한지 알려주세요. 나는 당신의 코드와 똑같이하고있다. – virantporwal
헤이 작동하도록 만들었습니까? @virantporwal에게 답장을 보내주세요. – va05