gpt4 book ai didi

c# - 如何从 ExecuteAsync() 方法获取字段

转载 作者:行者123 更新时间:2023-11-30 14:47:50 25 4
gpt4 key购买 nike

我熟悉如何在我的 Google Drive 中创建文件夹,但我正在考虑使用异步方法来执行此操作。但是,在这样做时,我不确定如何获取我明确添加到我希望返回的字段中的字段。

我的代码如下:

private Task<Google.Apis.Drive.v3.Data.File> CreateGoogleDriveFolderAsync(DriveService service, string foldername, string parent_id = null)
{
IList<string> parent_ids = new List<string>();

Google.Apis.Drive.v3.Data.File folder = new Google.Apis.Drive.v3.Data.File
{
Name = foldername
, MimeType = "application/vnd.google-apps.folder"
, Description = "Client Name: blah\nUser: Rudy\n"
};

var insert = service.Files.Create(folder);

// The field I'd like to get somewhere.
insert.Fields = "id";

var task = insert.ExecuteAsync();

task.ContinueWith(t =>
{
// NotOnRanToCompletion - this code will be called if the upload fails
Console.WriteLine("Failed to create folder \"{0}\": " + t.Exception, foldername);
}, TaskContinuationOptions.NotOnRanToCompletion);
task.ContinueWith(t =>
{
// I'd like a way to access "id" from my insert execution.
log.insertLogging(foldername, "Directory Created");
});

return task;
}

最佳答案

使用 documentation 中的示例, 等待 任务并从那里取回文件你应该可以访问它的属性

private async Task<File> CreateGoogleDriveFolderAsync(DriveService driveService, string foldername) {
var metadata = new File()
{
Name = foldername,
MimeType = "application/vnd.google-apps.folder"
};
var request = driveService.Files.Create(metadata);
request.Fields = "id";
var folder = await request.ExecuteAsync();
Console.WriteLine("Folder ID: " + folder.Id);

return folder;
}

关于c# - 如何从 ExecuteAsync() 方法获取字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43143226/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com