1

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:

Community
  • 1
  • 1
  • Seems like this is an issue with the request permissions (see [here](http://stackoverflow.com/q/22111801/4625829)), not with the API itself. – AL. May 13 '17 at 02:53
  • @SupriyaNale Any idea about 403 error from Google while trying to fetch Contacts, see here https://stackoverflow.com/questions/51614767/not-able-to-fetch-google-contacts-by-calling-api-in-swift – Anilkumar iOS - ReactNative Aug 01 '18 at 04:05

0 Answers0