当我请求使用GDATA获取所有联系人时出现错误401

时间:2015-01-20 06:36:01

标签: ios objective-c gdata

我正在使用Gdata并已经成功登录gmail并调用以下方法

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

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

在上面的方法中我得到了Authentifacation令牌等。 现在

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];
                  }
              }
          }]; 

但我收到错误401 请帮助我

0 个答案:

没有答案