0

In my application user logs in throgh google+ credentials for which I have implemented google+ framework for authentication/authorization. After Successful login I have to get the contacts list of the logged in user.

for which I am using Google Contacts API version 3.0 url https://www.google.com/m8/feeds/contacts/default/full

After GPP Sign In authentication request..

- (void)finishedWithAuth:(GTMOAuth2Authentication *)auth
                   error:(NSError *)error {
    if (error) {
        NSLog(@"%@",[NSString stringWithFormat:@"Status: Authentication error: %@", error]);
        return;
    }

    auth.clientID  =@"XXXX.apps.googleusercontent.com";
    auth.clientSecret  =@"xxxxxxxx-z7tmOqQCShgH3ax";


    NSString *urlStr = @"https://www.google.com/m8/feeds/contacts/default/full";
    NSURL *url = [NSURL URLWithString:urlStr];

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPMethod:@"GET"];
    [request setValue:@"3.0" forHTTPHeaderField:@"GData-Version"];

    auth.scope= @"https://www.googleapis.com/auth/contacts.readonly";
    [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];
                     NSLog(@"%@", output);
                 } else {
                     // fetch failed
                     output = [error description];
                 }
             }
         }];
}

in the successful response I have written code like this.

But the output is not as desired. The output string is huge junk value and at the end of it is showing

401. That's an error.

There was an error in your request. That's all we know.

Could any one please help in resolving the issue.

CKT
  • 1,223
  • 4
  • 21
  • 39

1 Answers1

0

401 means that you have not correctly authorized. I don't work with that api but it's possible your credentials are incorrect.

you might also be seeing certificate problems for the https? you should set up this call back and see if it provides more info.

How to use NSURLConnection to connect with SSL for an untrusted cert?

Community
  • 1
  • 1
madmik3
  • 6,975
  • 3
  • 38
  • 60
  • there is no problem with the credentials, If I use the same credentials with GData I am able to get the contacts. And I have implemented the NSURLConnection SSL certificate delegate methods which are mentioned in the link provided by you. What I found is there is no problem with the certificate also – CKT Nov 12 '14 at 14:00