使用Google Drive iOS API,如何创建文件夹并共享它?
GTLDriveFile * folder = [GTLDriveFile object];
folder.title = @"Test";
folder.mimeType = @"application/vnd.google-apps.folder";
// ???
答案 0 :(得分:0)
可能这个可以帮到你。此代码用于创建具有特定名称的文件夹。
代码1:
-(void)createFolderWithName:(NSString *)folderName {
GTLDriveFile *file = [GTLDriveFile object];
file.title = @"FileUpload";
file.mimeType = @"application/vnd.google-apps.folder";
// To create a folder in a specific parent folder, specify the identifier
// of the parent:
// _resourceId is the identifier from the parent folder. Here i am using root as the parent folder.
NSString *resourceId = @"root";
if (resourceId.length && ![resourceId isEqualToString:@"0"]) {
GTLDriveParentReference *parentRef = [GTLDriveParentReference object];
parentRef.identifier = resourceId;
file.parents = [NSArray arrayWithObject:parentRef];
}
GTLQueryDrive *query1 = [GTLQueryDrive queryForFilesInsertWithObject:file uploadParameters:nil];
[[self appDelegate].driveService executeQuery:query1 completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error) {
if (!error) {
//I see this in the console...
//No Errors in Folder Query:
//GTLDriveFileList 0x108f3430: {kind:"drive#fileList"
//etag:""Q5ElJByAJoL0etObruYVPRipH1k/vyGp6PvFo4RvsFtPoIWeCReyIC8""}
NSLog(@"No Errors in Folder Query: %@",object);
GTLDriveFileList *list = (GTLDriveFileList *)object;
//So, none of this for() loop happens
for (GTLDriveFile *file in list.items) {
NSLog(@"Folder: \n \n %@ \n \n",file);
//NSLog(@"\n file extension value is %@",file.fileExtension);
//NSLog(@"\n file size value is %@",file.fileSize);
}
} else {
NSLog(@"Folder Query Error: %@",error);
}
}];
}
在上面的代码中,resourceId是父文件夹id,您想在其下创建文件夹。
我不知道如何分享整个文件夹,但我认为它与共享文件一样。
如果您想了解特定文件共享,请参阅此链接。在链接中,您可以找到objective-c代码的示例。 https://developers.google.com/drive/v2/reference/permissions/insert