private async Task DisplayVolumes(BooksService service, Bookshelves bookshelves) { if (bookshelves.Items == null) { Console.WriteLine("No bookshelves found!"); return; } foreach (Bookshelf item in bookshelves.Items) { Console.WriteLine(item.Title + "\t" + (item.VolumeCount.HasValue ? item.VolumeCount + " volumes" : "")); // List all volumes in this bookshelf. if (item.VolumeCount > 0) { Console.WriteLine("Query volumes... (Execute ASYNC)"); Console.WriteLine("--------------------------------"); var request = service.Mylibrary.Bookshelves.Volumes.List(item.Id.ToString()); Volumes inBookshelf = await request.ExecuteAsync(); if (inBookshelf.Items == null) { continue; } foreach (Volume volume in inBookshelf.Items) { Console.WriteLine("-- " + volume.VolumeInfo.Title + "\t" + volume.VolumeInfo.Description ?? "no description"); Console.WriteLine(); } } } }
public async Task <GooglePayload> ValidateBearerTokenAsync(string authCode) { var authorizationCodeFlow = new GoogleAuthorizationCodeFlow( new GoogleAuthorizationCodeFlow.Initializer { ClientSecrets = new ClientSecrets() { ClientId = _identityOptions.GoogleClientId, ClientSecret = _identityOptions.GoogleClientSecret } }); TokenResponse tokenResponse = await authorizationCodeFlow .ExchangeCodeForTokenAsync("me", authCode, "http://localhost:8080", CancellationToken.None); UserCredential userCredential = new UserCredential(authorizationCodeFlow, "me", tokenResponse); BooksService booksService = new BooksService(new BaseClientService.Initializer { HttpClientInitializer = userCredential }); Bookshelves test = await booksService.Mylibrary.Bookshelves.List().ExecuteAsync(); Payload payload = await ValidateAsync(tokenResponse.IdToken, GetValidationSettings()); return(new GooglePayload(payload, tokenResponse.AccessToken, tokenResponse.RefreshToken)); }
public Bookshelf GetBookshelf(string name) => Bookshelves.Find(bs => bs.Name == name);