Google Drive API-使用Objective-C列出特定文件夹中的特定文件

Google Drive API-使用Objective-C列出特定文件夹中的特定文件,objective-c,google-drive-api,google-drive-realtime-api,Objective C,Google Drive Api,Google Drive Realtime Api,我正在为iOS开发谷歌硬盘集成,遇到了一个难题——我需要检查文件夹中是否存在文件,但无论我如何整理请求,我都会收到“500内部错误”响应。我认为这应该是合法的: // self.directoryDriveFile.identifier is a valid folder identifier retrieved on previous request GTLQueryDrive *query = [GTLQueryDrive queryForChildrenListWithFolderId:s

我正在为iOS开发谷歌硬盘集成,遇到了一个难题——我需要检查文件夹中是否存在文件,但无论我如何整理请求,我都会收到“500内部错误”响应。我认为这应该是合法的:

// self.directoryDriveFile.identifier is a valid folder identifier retrieved on previous request
GTLQueryDrive *query = [GTLQueryDrive queryForChildrenListWithFolderId:self.directoryDriveFile.identifier];

// add query to specify the file we're interested in (works in Java version...)
query.q = [NSString stringWithFormat:@"title='%@' and trashed=false",
           ZTCloudSyncLockFileName];
// stopping in debugger shows query.q: title='sync.lock' and trashed=false

// fire off request
[self.driveService executeQuery:query
              completionHandler:^(GTLServiceTicket *ticket,
                                  GTLDriveFileList *files,
                                  NSError *error) {
                  if (error == nil) {
                      if ([files.items count] > 0) {
                          self.foundLockfile = YES;
                      } else {
                          self.foundLockfile = NO;
                      }
                  } else {
                      DLog(@"An error occurred loading lockfile request: %@", error);
                      [self bailWithError:error performCleanup:NO];
                  }
              }];
执行查询时,它总是以错误告终,错误信息如下:

Error Domain=com.google.GTLJSONRPC
ErrorDomain Code=500 "The operation couldn’t be completed. (Internal Error)" 
UserInfo=0x99c4660 {
  error=Internal Error, 
  GTLStructuredError=GTLErrorObject 0x99c4360: {
  message:"Internal Error" code:500 data:[1]}, 
  NSLocalizedFailureReason=(Internal Error)}
我还尝试了以下更基本的查询,指定了一个
parents
子句,但最终得到了上面显示的相同错误对象:

GTLQueryDrive *altQuery = [GTLQueryDrive queryForFilesList];
altQuery.q = [NSString stringWithFormat:@"title='%@' and trashed=false and '%@' in parents",
              ZTCloudSyncLockFileName,
              self.directoryDriveFile.identifier];
这也应该有效,但也会产生500的误差


附加信息:在进行此操作时测试了以下各项:

  • 检查根目录中的文件夹是否正确
  • 在根目录中创建文件夹确定吗
  • 检查根目录中名为sync.lock的文件确定
您可以使用上述方法获取文件夹内容。 这是福德里德

  • “根”(主驱动器)
  • 共享文件夹的“sharedWithMe”
  • GTLDrivefile标识符值

您是否使用服务帐户?瞧:我不知道你的意思。查看了链接,但没有解释“服务帐户”。我正在以入门obj-c教程和其他示例中描述的方式使用API。@BillyGray您应该像我一样包括您评论的目标人,否则他将不会得到通知,也可能不会回来回复您的评论。@ilmiacs谢谢您的提示!可惜的是,移动网站上没有自动完成功能(无论如何,目前还没有)。干杯。看起来这可能是一个与标题查询和drive.file作用域相关的bug,而不是objective-c代码(看起来不错)
-(void)fetchGoogleDriveFileListWithfolderId:(NSString *)folderId
    :(void (^)(NSMutableArray *, NSError*))completionBlock
{
    GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
    query.q =[NSString stringWithFormat:@"'%@' in parents and trashed=false", folderId];

    GTLServiceTicket *ticketListing = [self.driveService
        executeQuery:query completionHandler:^(GTLServiceTicket *ticket,GTLDriveFileList *files, NSError *error)
    {
        NSMutableArray *mainArray=[[NSMutableArray alloc]init];

        if (error == nil)
        {
            completionBlock(files.items,nill);
        }
        else
        {
            NSLog(@"An error occurred: %@", error);
            completionBlock(nil,error);
        }
    }];
}