Google Drive API - 使用Objective-C在特定文件夹中列出特定文件 [英] Google Drive API - list specific files in a specific folder using Objective-C
问题描述
我正在研究iOS版Google云端硬盘集成,并且遇到了一些问题 - 我需要检查文件夹中是否存在文件,但无论如何我都会收到500内部错误响应我似乎把这个要求放在一起。我认为这应该是合法的:
// self.directoryDriveFile.identifier是在前一个请求中检索的有效文件夹标识
GTLQueryDrive * query = [GTLQueryDrive queryForChildrenListWithFolderId:self.directoryDriveFile.identifier];
//添加查询以指定我们感兴趣的文件(在Java版本中工作...)
query.q = [NSString stringWithFormat:@title ='%@'和trashed = false,
ZTCloudSyncLockFileName];
//在调试器中停止显示query.q:title ='sync.lock'和trashed = false
//发出请求
[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;
}其他{
DLog(@加载锁定文件请求时发生错误:%@,错误);
[self bailWithError:error performCleanup:NO];
}
}];
当执行查询时,它总是以错误结尾,并带有以下不幸的稀疏错误信息:
错误域= com.google.GTLJSONRPC
ErrorDomain代码= 500无法完成操作。(内部错误)
UserInfo = 0x99c4660 {
error =内部错误,
GTLStructuredError = GTLErrorObject 0x99c4360:{
message:内部错误代码:500 data:[1]} ,
NSLocalizedFailureReason =(内部错误)}
我也尝试了以下更基本的查询,指定一个父母
子句,但我最后得到上面显示的同样不幸的备用错误对象:
GTLQueryDrive * altQuery = [GTLQueryDrive queryForFilesList];
altQuery.q = [NSString stringWithFormat:@title ='%@'和trashed = false以及父母中的'%@',
ZTCloudSyncLockFileName,
self.directoryDriveFile.identifier];
这也应该有效,但也会产生500个错误。
其他信息:在此过程中测试以下内容:
- (void)fetchGoogleDriveFileListWithfolderId :( NSString *)folderId
:(void(^)(NSMutableArray *,NSError *))completionBlock
{
GTLQueryDrive * query = [GTLQueryDrive queryForFilesList];
query.q = [NSString stringWithFormat:@''%@'在父母和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是
$ b $ ul
$ root $(主驱动器)
I'm working on a Google Drive integration for iOS and I've hit a snag—I need to check for the existence of a file in a folder, but I keep getting a "500 Internal Error" response no matter how I seem to put together the request. I think this should be legit:
// 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];
}
}];
When the query is executed, it always ends up in error, with the following unfortunately sparse error information:
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)}
I've also tried the following more basic query, specifying a parents
clause, but I end up with the same unfortunately spare error object shown above:
GTLQueryDrive *altQuery = [GTLQueryDrive queryForFilesList];
altQuery.q = [NSString stringWithFormat:@"title='%@' and trashed=false and '%@' in parents",
ZTCloudSyncLockFileName,
self.directoryDriveFile.identifier];
That, too, should work, but also produces a 500 error.
Additional information: tested the following while working on this:
- Check for folder in directory root—OK
- Create folder in directory root—OK
- Check for file named sync.lock in directory root—OK
-(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);
}
}];
}
You can use above method for fetch the folder contents. Here folderId is
- "root" (Main Drive)
- "sharedWithMe" for shared folder
- GTLDrivefile identifier value
这篇关于Google Drive API - 使用Objective-C在特定文件夹中列出特定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!