public async Task <List <GoodReadsBookDTO> > SearchByTitle(string title) { const string apiKey = "hG8Baz6PR4BYmKheAD3qg"; const string apiSecret = "0nyS2sEH9JKSWil0j5xOBdcB6BzLmxscoo8yAIk"; var client = GoodreadsClient.Create(apiKey, apiSecret); var books = await client.Books.Search(title, 1, Goodreads.Models.Request.BookSearchField.Title); var goodReadsBooks = new List <GoodReadsBookDTO>(); foreach (var book in books.List) { var goodReadsBook = new GoodReadsBookDTO() { Author = book.BestBook.AuthorName, Title = book.BestBook.Title, ImageURL = book.BestBook.ImageUrl, GoodReadsBookId = book.BestBook.Id }; goodReadsBooks.Add(goodReadsBook); } return(goodReadsBooks); }
//public Task<PaginatedList<Work>> Search(string querySearch) //{ // var client = GoodreadsClient.Create(apiKey, apiSecret); // return client.Books.Search(querySearch); //} public Task <SearchResult> SearchByTitle(string querySearch) { return(Task.Run(() => { var configurationBuilder = new ConfigurationBuilder() .AddUserSecrets("HW9Secrets"); var config = configurationBuilder.Build(); string goodreadsKey = config["goodreadsKey"]; string goodreadsSecret = config["goodreadsSecret"]; var client = GoodreadsClient.Create(goodreadsKey, goodreadsSecret); SearchResult result = new SearchResult(); var val = client.Books.GetByTitle(querySearch).Result; if (val != null) { result.RelatedBooks = new ObservableCollection <SearchResult>(); foreach (var p in val.Authors) { result.Author += p.Name + ", "; } result.Title = val.Title; result.Image = val.SmallImageUrl; if (val.SimilarBooks != null) { foreach (var b in val.SimilarBooks) { SearchResult otherBook = new SearchResult(); foreach (var o in b.Authors) { otherBook.Author += o.Name + ", "; } otherBook.Title = b.Title; otherBook.Image = b.SmallImageUrl; result.RelatedBooks.Add(otherBook); } } else { SearchResult otherBook = new SearchResult { Title = "Not Available", Image = "Not Available", Author = "Not Available" }; result.RelatedBooks.Add(otherBook); } } else { result.RelatedBooks = new ObservableCollection <SearchResult>(); result.Title = "Not able to get info"; result.Author = "Not Able to get info"; result.Image = "Not Able to get info"; } return result; })); }
public GoodReadsDataSource(IPreferenceService preferenceService) { _preferenceService = preferenceService; _client = GoodreadsClient.Create( preferenceService.Get("goodreads.apikey", "ckvsiSDsuqh7omh74ZZ6Q"), // todo: this is the lazylibrarian key... preferenceService.Get("goodreads.apisecret", "") ); }
public async Task <ActionResult <IEnumerable <string> > > Get(string isbn) { const string apiKey = "hG8Baz6PR4BYmKheAD3qg"; const string apiSecret = "0nyS2sEH9JKSWil0j5xOBdcB6BzLmxscoo8yAIk"; var client = GoodreadsClient.Create(apiKey, apiSecret); var book = await client.Books.GetByIsbn(isbn); return(Ok(book)); }
// GET: Home public async Task IndexAsync(string booksName) { //https://www.goodreads.com/search/index.xml?key=Axm8msC1oG3ZqXyqlO5Ng&q=harry&search%5Bfield%5D=title // Create an unauthorized Goodreads client. var client = GoodreadsClient.Create(apiKey, apiSecret); // Now you are able to call some Goodreads endpoints that don't need the OAuth credentials. For example: // Get a book by specified id. Book kitap = await client.Books.GetByTitle(booksName); string authorname = ""; foreach (var item in kitap.Authors) { authorname += item.Name + " & "; } authorname = authorname.Substring(0, authorname.Length - 3); //db yazar AuthorService _authorService = new AuthorService(); Common.Domains.Author author = new Common.Domains.Author { Name = authorname }; await _authorService.Add(author); //db image ProductService _productService = new ProductService(); Product book = new Product { AuthorId = _authorService.GetByName(authorname).Id, ImageUrl = kitap.ImageUrl, Description = kitap.Description, Verify = false, Name = kitap.Title }; await _productService.Add(book); CategoryService _categoryService = new CategoryService(); foreach (var item in kitap.PopularShelves) { Common.Domains.Category categories = new Category { Name = item.Key, ProductID = _productService.GetByName(kitap.Title).Id }; await _categoryService.Add(categories); } }
public async Task <IActionResult> OnPostAsync() { // Create an unauthorized Goodreads client. var client = GoodreadsClient.Create(Storage.ApiKey, Storage.ApiSecret); // Ask a Goodreads request token and build an authorization url. var callbackUrl = Url.Page("Callback", null, null, Request.Scheme); var requestToken = await client.AskCredentials(callbackUrl); // Save user token for future used. Storage.SaveToken(requestToken.Token, requestToken.Secret); // Redirect to Goodreads auth page. return(Redirect(requestToken.AuthorizeUrl)); }
public BookService() { //get goodread developer key and developer secret key var appSettings = ConfigurationManager.AppSettings; var GOODREADS_KEY = appSettings.Get("GOODREADSKEY"); var GOODREADS_SECRET = appSettings.Get("GOODREADSSECRET"); //connect a client var client = GoodreadsClient.Create(GOODREADS_KEY, GOODREADS_SECRET); const string callbackUrl = "<no-callback>"; var requestToken = client.AskCredentials(callbackUrl).GetAwaiter().GetResult(); var accessToken = client.GetAccessToken(requestToken).GetAwaiter().GetResult(); _authClient = GoodreadsClient.CreateAuth(GOODREADS_KEY, GOODREADS_SECRET, accessToken.Token, accessToken.Secret); }
private async Task Btn_populate_Clicked(object sender, EventArgs e) { if (Ent_isbn.Text == string.Empty | Ent_isbn.Text == null) { await DisplayAlert("Warning", "Please enter book ISBN", "OK"); return; } try { var client = GoodreadsClient.Create(apiKey, apiSecret); var localbook = await client.Books.GetByIsbn(Ent_isbn.Text); Ent_title.Text = localbook.Title; //---------Convert HTML to plain Text for Description------------- var pageContent = localbook.Description; var pageDoc = new HtmlDocument(); pageDoc.LoadHtml(pageContent); Ent_desc.Text = pageDoc.DocumentNode.InnerText; //---------------------- //Ent_desc.Text = localbook.Description; Ent_img.Text = localbook.ImageUrl; string tempAuth = ""; foreach (var author in localbook.Authors) { tempAuth = tempAuth + author.Name + ", "; } Ent_author.Text = tempAuth.Trim().Trim(','); } catch { await DisplayAlert("Error", "Error in fetching data, Enter manually.", "OK"); } }
/// <summary> /// Callback get handler. /// </summary> /// <param name="oauth_token">A public OAuth token.</param> /// <param name="authorize">Determine whether user has been already auth or not.</param> /// <returns></returns> public async Task OnGetAsync(string oauth_token, int authorize) { if (authorize == 0) { Message = $"Oops, seems you didn't grant an access for the Demo application."; return; } // Create an unauthorized Goodreads client. var client = GoodreadsClient.Create(Storage.ApiKey, Storage.ApiSecret); // Get a user's OAuth access token and secret after they have granted access. var accessToken = await client.GetAccessToken(oauth_token, Storage.GetSecretToken(oauth_token)); // Create an authorized Goodreads client. var authClient = GoodreadsClient.CreateAuth(Storage.ApiKey, Storage.ApiSecret, accessToken.Token, accessToken.Secret); // Get information for the current user. var currentUserId = await authClient.Users.GetAuthenticatedUserId(); var user = await authClient.Users.GetByUserId(currentUserId); Message = $"Welcome {user.Name}"; }
public GoodReadsApi() { this._client = GoodreadsClient.Create(Constants.GoodReadsApiKey, Constants.GoodReadsApiSecret); }
public GoodreadsApi(string apiKey, string apiSecret) { client = GoodreadsClient.Create(apiKey, apiSecret); }
public static IGoodreadsClient GetClient() { return(GoodreadsClient.Create( Environment.GetEnvironmentVariable("GOODREADS_APIKEY"), Environment.GetEnvironmentVariable("GOODREADS_APISECRET"))); }