如何使用目标C在Google云端硬盘中创建文件夹?

时间:2014-08-25 13:17:14

标签: ios objective-c iphone google-drive-api

我需要在google驱动器中创建一个文件夹。请告诉我如何创建一个文件夹。我将以下链接引用到创建文件夹。 how to create folder on Google Drive using Google Drive SDK for iPhone?

但没用。请帮我如何创建一个文件夹。

2 个答案:

答案 0 :(得分:0)

  GTLDriveFile *folderObj = [GTLDriveFile object];
        folderObj.title = tempString;
        folderObj.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
        if (driveFilesId.length && ![driveFilesId isEqualToString:@"0"]) {
            GTLDriveParentReference *parentRef = [GTLDriveParentReference object];
            parentRef.identifier = driveFilesId;
            folderObj.parents = [NSArray arrayWithObject:parentRef];
        }

        GTLQueryDrive *query = [GTLQueryDrive queryForFilesInsertWithObject:folderObj uploadParameters:nil];
        GTLServiceTicket *queryTicket =
        [[DriveHelperClass getSharedInstance].driveService executeQuery:query
            completionHandler:^(GTLServiceTicket *ticket, id object,
                                NSError *error) {
                if (!error) {
                    [[NSNotificationCenter defaultCenter] postNotificationName:@"DropboxCreateFolderSuccess" object:self userInfo:nil];
                    [MBProgressHUD hideHUDForView:self.view animated:YES];
                    [self viewWillAppear:YES];
                    [tbDownload reloadData];                }
                else
                {
                    NSLog(@"error %@",error);
                }
            }];

答案 1 :(得分:0)

  

对于创建文件夹,请调用以下函数并将文件夹名称,GTLServiceDrive对象和父ID作为参数传递

+(void)createFolderName:(NSString *)folderName wihDriverservice:(GTLServiceDrive *)driveService OfParent:(NSString *)parentId WithCompletionBlock:(void (^)(GTLDriveFile *, NSError*))completionBlock{

GTLDriveParentReference *parent = [GTLDriveParentReference object];
parent.identifier = parentId;

GTLDriveFile *folder = [GTLDriveFile object];
folder.title =folderName;
folder.mimeType = @"application/vnd.google-apps.folder";
folder.parents = @[parent];

GTLQueryDrive *query = [GTLQueryDrive queryForFilesInsertWithObject:folder uploadParameters:nil];
[driveService executeQuery:query completionHandler:^(GTLServiceTicket *ticket,
                                             GTLDriveFile *updatedFile,
                                             NSError *error) {
    if (error == nil) {
        NSLog(@"Created folder");
        completionBlock(updatedFile, nil);

    } else {
        completionBlock(nil, error);
        NSLog(@"An error occurred: %@", error);
    }
}];

}