Error 401 when I request all contacts using GDATA

I am using Gdata and can already fully log into gmail and call the method below

 - (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController
  finishedWithAuth:(GTMOAuth2Authentication *)auth{
  if (error != nil) {

   }
  else{
     // i got successful login here
     self.auth=auth;
  }
}

in the above method, I got an authentication token, etc. Now

NSString *urlStr =   @"https://www.google.com/m8/feeds/contacts/default/full";
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 {
                  // Synchronous fetches like this are a really bad idea in Cocoa applications
                  //
                  // For a very easy async alternative, we could use GTMHTTPFetcher
                  NSURLResponse *response = nil;
                  NSData *data = [NSURLConnection sendSynchronousRequest:request
                                                       returningResponse:&response
                                                                   error:&error];
                  if (data) {
                      // API fetch succeeded
                      output = [[[NSString alloc] initWithData:data
                                                      encoding:NSUTF8StringEncoding] autorelease];


                                           } else {
                      // fetch failed
                      output = [error description];
                  }
              }
          }]; 

but i got error 401 please help me

+4
source share

All Articles