我尝试使用Google Drive SDK for iOS创建文件夹。 我使用如下代码,创建文件夹内部的主驱动器创建。
GTLDriveFile *folder = [GTLDriveFile object];
folder.title = @"Testing";
folder.mimeType = @"application/vnd.google-apps.folder";
NSString *parentId = @"Testing";
folder.parents = @[parentId];
// ... execute query
GTLQueryDrive *query1 = [GTLQueryDrive queryForFilesInsertWithObject:folder uploadParameters:nil];
[self.driveService executeQuery:query1 completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFile *updatedFile,
NSError *error)
{
if (error == nil)
{
NSLog(@"Created folder %@",updatedFile.identifier);
GTLDriveParentReference *parentReference = [GTLDriveParentReference object];
parentReference.identifier = updatedFile.identifier;
GTLDriveFile *subFolder = [GTLDriveFile object];
subFolder.title = @"Testing12352";
subFolder.mimeType = @"application/vnd.google-apps.folder";
NSString *parentId = updatedFile.identifier;
subFolder.parents = @[parentReference];
// ... execute query
GTLQueryDrive *query1 = [GTLQueryDrive queryForFilesInsertWithObject:folder uploadParameters:nil];
[self.driveService executeQuery:query1 completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFile *updatedFile,
NSError *error)
{
if (error == nil)
{
NSLog(@"Created folder %@",updatedFile.parents);
}
}];
工作完美。 Google驱动器文件夹内部文件夹创建..
答案 0 :(得分:1)
如果您要在Testing
和root
Testing12352
文件夹中创建Testing
文件夹,那么对于Testing
,您需要将parents
设置为[@"root"]
和Testing12352
您需要将测试identifier
设置为parents
。
GTLDriveFile *folder = [GTLDriveFile object];
folder.title = @"Testing";
folder.mimeType = @"application/vnd.google-apps.folder";
NSString *parentId = @"root";
folder.parents = @[parentId];
// ... execute query
GTLQueryDrive *query1 = [GTLQueryDrive queryForFilesInsertWithObject:folder uploadParameters:nil];
[self.driveService executeQuery:query1 completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFile *updatedFile,
NSError *error)
{
if (error == nil)
{
NSLog(@"Created folder %@",updatedFile.identifier);
GTLDriveFile *subFolder = [GTLDriveFile object];
subFolder.title = @"Testing12352";
subFolder.mimeType = @"application/vnd.google-apps.folder";
NSString *parentId = updatedFile.identifier;
subFolder.parents = @[parentId];
// ... execute query
GTLQueryDrive *query1 = [GTLQueryDrive queryForFilesInsertWithObject:subFolder uploadParameters:nil];
[self.driveService executeQuery:query1 completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFile *updatedFile,
NSError *error)
{
if (error == nil)
{
NSLog(@"Created folder %@",updatedFile.parents);
}
}];
注意:请勿忘记将scope
设为kGTLAuthScopeDrive