Я инициализировал службу API Google и передал ее методу «Создать папку», каждый раз, когда он создает одну и ту же папку в Google Диске, я хочу применить логи c Если папка существует, не создавайте ее, просто возвращайте его FolderID еще создайте новую папку и верните ее идентификатор папки. Пожалуйста, предложите это.
var service= InitializeGoogleDriveAPIService(clientId, clientSecret);
var res=CreateFolder(service, "FolderName");
private static DriveService InitializeGoogleDriveAPIService(string clientId, string clientSecret)
{
string[] scopes = new string[] { DriveService.Scope.Drive, DriveService.Scope.DriveFile, };
ClientSecrets clientSecrets = new ClientSecrets();
clientSecrets.ClientId = clientId;
clientSecrets.ClientSecret = clientSecret;
// Below is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData%
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(clientSecrets, scopes, Environment.UserName, CancellationToken.None, new FileDataStore("MyAppsToken")).Result;
//Once consent is received, the token will be stored locally on the AppData directory,
//so that next time we won't be prompted for consent. -one time setting for the Console app
BaseClientService.Initializer initializer = new BaseClientService.Initializer();
initializer.HttpClientInitializer = credential;
initializer.ApplicationName = "PRInvoices";
DriveService service = new DriveService(initializer);
service.HttpClient.Timeout = TimeSpan.FromMinutes(100);
//Long Operations like file uploads might timeout. 100 is just precautionary value,
//can be set to any reasonable value depending on what you use your service for
return service;
}
public static string CreateFolder(DriveService service, string folderName)
{
var file = new Google.Apis.Drive.v3.Data.File { Name = folderName, MimeType = "application/vnd.google-apps.folder" };
// var RESILT = service.Files.List();
var result = service.Files.Create(file).Execute();
return result.Id;
}