Created
June 26, 2014 10:05
-
-
Save matijagrcic/8f4adbf6c2ea1645ed29 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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