Skip to content

Instantly share code, notes, and snippets.

@matijagrcic
Created June 26, 2014 10:05
Show Gist options
  • Select an option

  • Save matijagrcic/8f4adbf6c2ea1645ed29 to your computer and use it in GitHub Desktop.

Select an option

Save matijagrcic/8f4adbf6c2ea1645ed29 to your computer and use it in GitHub Desktop.
public async Task ListLabels()
{
UserCredential credential;
using (var stream = new FileStream("client_secrets_desktop.json", FileMode.Open, FileAccess.Read))
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets,
new[] { GmailService.Scope.GmailReadonly },
"user", CancellationToken.None);
}
var service = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Gmail Test",
});
try
{
ListLabelsResponse response = service.Users.Labels.List("me").Execute();
foreach (Label label in response.Labels.OrderBy(p=>p.Name))
{
Console.WriteLine(label.Id + " - " + label.Name);
}
}
catch (Exception e)
{
Console.WriteLine("An error occurred: " + e.Message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment