I am trying to fetch the google contacts(Gmail contacts i.e https://contacts.google.com
) in my iOS application but unable to fetch. I had tried to use bellow API for fetching all contacts: https://www.google.com/m8/feeds/contacts/default/full
Here is code snippet :
- (void)fetchGoogleContacts {
NSString *urlStr = @"https://www.google.com/m8/feeds/contacts/default/full";
NSURL *url = [NSURL URLWithString:urlStr];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[_authorization 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];
NSError *jsonError = nil;
id jsonDictionaryOrArray = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
NSLog(@"jsonDictionaryOrArray : %@", jsonDictionaryOrArray);
} else {
// fetch failed
output = [error description];
}
}
}];
}
There is no error in completionHandler, but it shows error on bellow step
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
and error is
Error Domain=NSURLErrorDomain Code=-1012 "(null)" UserInfo={NSErrorFailingURLStringKey=https://www.google.com/m8/feeds/contacts/default/full, NSUnderlyingError=0x600000054460 {Error Domain=kCFErrorDomainCFNetwork Code=-1012 "(null)" UserInfo={_kCFURLErrorAuthFailedResponseKey={url = https://www.google.com/m8/feeds/contacts/default/full}}}, NSErrorFailingURLKey=https://www.google.com/m8/feeds/contacts/default/full}
Help me to sort this issue and to fetch all google contacts. Thanks in advance.
Following suggestions are not working at my side: