如何在谷歌驱动器中获取文件夹的ID使用目标c

时间:2014-03-04 03:10:55

标签: objective-c google-app-engine google-drive-api

我想在将文件夹上传到Google云端硬盘时立即获取该文件夹的标识符。 例如:

- (NSString *) folderupload:(NSString *)parentid
           foldername:(NSString *)foldername
{
    GTLDriveFile *folderObj = [GTLDriveFile object];
    folderObj.title = foldername;
    folderObj.mimeType = @"application/vnd.google-apps.folder";
    GTLDriveParentReference *parentRef = [GTLDriveParentReference object];
    parentRef.identifier = parentid;
    folderObj.parents = [NSArray arrayWithObject:parentRef];
    GTLQueryDrive *query = [GTLQueryDrive queryForFilesInsertWithObject:folderObj
                                                       uploadParameters:nil];
    NSString *identify = nil;
    [service executeQuery:query
    completionHandler:^(GTLServiceTicket *ticket,
                        GTLDriveFile *insertedFile,
                        NSError *error){
        if (error == nil) {
            identify = insertedFile.identifier;
            NSLog(@"OK");
        } else {
            NSLog(@"%@ upload ERROR!",localpath);
            int value = arc4random() % 2;
            sleep(4+value);
            [self fileupload:localpath
                    filename:filename
                    mimetype:mimetype
                    parentid:parentid];
            NSLog(@"try again");
        }
    }];
    return identify;
}

但是当我调用方法folderupload时,方法返回null,并且方法上传文件夹成功。如何获取文件夹的id?

0 个答案:

没有答案