How to get fields from ExecuteAsync () method
I am familiar with creating a folder in my Google Drive, but I am doing this using an asynchronous method. However, when doing this, I am not sure how to get the field that I have explicitly added to the fields that I would like to return.
My code is below:
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;
}
+3
source to share
1 answer
Using the example from the documentation , await
setting and getting the file back, you should have access to its properties
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;
}
+4
source to share