using Google.Apis.Auth.OAuth2; using Google.Apis.Gmail.v1; using Google.Apis.Services; using Google.Apis.Util.Store; namespace GmailArneMoermanSorter { internal class Program { static void Main(string[] args) { Console.WriteLine("Access emails over Gmail Api"); try { new Program().Run().Wait(); } catch (Exception e) { Console.WriteLine(e); throw; } } private async Task Run() { UserCredential credential; using (var stream = new FileStream("clientSecret.json", FileMode.Open, FileAccess.Read)) { credential = await GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.FromStream(stream).Secrets, new[] {GmailService.Scope.GmailLabels}, "user", CancellationToken.None, new FileDataStore("GmailApi.Auth.Store")); } var service = new GmailService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "GmailArneMoermanSorter" }); var labels = await service.Users.Labels.List("me").ExecuteAsync(); foreach (var label in labels.Labels) { Console.WriteLine(label.Name); } } } }