无法从iOS中的Google云端硬盘中获取文件

这是我的代码。

GTLQueryDrive *query = [GTLQueryDrive queryForFilesList]; query.q = [NSString stringWithFormat:@"'%@' IN parents", @"root"]; [self.driveService executeQuery:query completionHandler:^(GTLServiceTicket *ticket,GTLDriveFileList *files, NSError *error) { if (error == nil) { if (self.driveFiles == nil) { self.driveFiles = [[NSMutableArray alloc] init]; } [self.driveFiles removeAllObjects]; [self.driveFiles addObjectsFromArray:files.items]; [tbDownload reloadData]; } else { NSLog(@"An error occurred: %@", error); } }]; 

我通过使用这个代码得到错误。

(error Error Domain=com.google.GTLJSONRPCErrorDomain Code=401 "The operation couldn't be completed. (Login Required)" UserInfo=0x8f72a40 {error=Login Required, GTLStructuredError=GTLErrorObject 0x8f647a0: {message:"Login Required" code:401 data:[1]}, NSLocalizedFailureReason=(Login Required)}

我已经login谷歌驱动器在我的应用程序。

您可能没有configuration您的GTLServiceDrive GTMOAuth2Authentication实例成功validation后获得。

示例代码:

 - (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController finishedWithAuth:(GTMOAuth2Authentication *)authResult error:(NSError *)error { if (error) { // Auth failed, handle the error } else { self.driveService.authorizer = authResult; } }