Files
Arne Moerman 411f4eb774 initial commit
2024-12-15 18:56:09 +01:00

48 lines
1.4 KiB
C#

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);
}
}
}
}