public static void CredentialDriveServiceByToken() { if (DriveService == null) { UserCredential credential; using (var stream = new FileStream(credentialPath, FileMode.Open, FileAccess.Read)) { string credPath = "token.json"; credential = GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, new string[] { DriveService.Scope.DriveReadonly }, "user", CancellationToken.None, new FileDataStore(credPath, true)).Result; Console.WriteLine("Credential file saved to: " + credPath); } // Create Drive API service. var service = new DriveService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = ApplicationName, }); DriveService = service; DriveManager.Init(service); } }