2

我正在开发适用于 iOS 的 Google Drive 集成,但遇到了一个问题——我需要检查文件夹中是否存在文件,但无论我看起来如何,我都会收到“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 的文件—确定
4

1 回答 1

0
-(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);
        }
    }];
}

您可以使用上述方法获取文件夹内容。这里 folderId 是

  • “根”(主驱动器)
  • 共享文件夹的“sharedWithMe”
  • GTLDrivefile 标识符值
于 2014-10-15T01:59:48.417 回答