private static void ItemSearch() { // Create the request object ItemSearchRequest request = new ItemSearchRequest(); // Fill request object with request parameters request.ResponseGroup = new string[] { "Large", "ItemAttributes", "AlternateVersions" }; // Set SearchIndex to All and use the scanned EAN // as the keyword, this should generate a single response request.SearchIndex = "Books"; request.Keywords = "Century rain"; // asin = 0441013074 request.Author = "Alastair Reynolds"; // Make the item search ItemSearch search = new ItemSearch(); // It is ABSOLUTELY CRITICAL that you change // the AWSAccessKeyID to YOUR uniqe value // Signup for an account (and AccessKeyID) at http://aws.amazon.com/ search.AWSAccessKeyId = access_key_id; search.AssociateTag = associate_tag; // Set the request on the search wrapper - multiple requests // can be submitted on one search search.Request = new ItemSearchRequest[] { request }; // Make the port AWSECommerceServicePortTypeClient port = new AWSECommerceServicePortTypeClient("AWSECommerceServicePort"); port.ChannelFactory.Endpoint.EndpointBehaviors.Add(new AmazonSigningEndpointBehavior(access_key_id, secret_access_key)); //Send the request, store the response and display some of the results ItemSearchResponse response = port.ItemSearch(search); foreach (var items in response.Items) { foreach (var item in items.Item) { Console.WriteLine("{0}\t{1}\t{2}", item.ItemAttributes.Title, item.ASIN, item.ItemAttributes.Author[0]); if (item.AlternateVersions != null) { Console.WriteLine(" - Alternate versions"); foreach (var version in item.AlternateVersions) { Console.WriteLine(" -- \t{0}\t{1}\t{2}", version.Title, version.Binding, version.ASIN); } } } } }
static void Main(string[] args) { var ci = CultureInfo.InvariantCulture.Clone() as CultureInfo; ci.NumberFormat.NumberDecimalSeparator = "."; List<string> products = new List<string>(); List<string> price = new List<string>(); // Instantiate Amazon ProductAdvertisingAPI client AWSECommerceServicePortTypeClient amazonClient = new AWSECommerceServicePortTypeClient(); for (int i = 1; i <= 6; i++) { // prepare an ItemSearch request ItemSearchRequest request = new ItemSearchRequest(); request.SearchIndex = "All"; //request.Title = "WCF"; request.Keywords = "playstation -kindle"; request.ResponseGroup = new string[] {"ItemAttributes", "Images"}; request.ItemPage = i.ToString(); ItemSearch itemSearch = new ItemSearch(); itemSearch.Request = new ItemSearchRequest[] { request }; itemSearch.AWSAccessKeyId = ConfigurationManager.AppSettings["accessKeyId"]; itemSearch.AssociateTag = "testfo-20"; // send the ItemSearch request ItemSearchResponse response = amazonClient.ItemSearch(itemSearch); } }
static void Main(string[] args) { // Instantiate Amazon ProductAdvertisingAPI client AWSECommerceServicePortTypeClient amazonClient = new AWSECommerceServicePortTypeClient(); // prepare an ItemSearch request ItemSearchRequest request = new ItemSearchRequest { SearchIndex = "Books", Title = "WCF", ResponseGroup = new[] { "Small" } }; ItemSearch itemSearch = new ItemSearch { Request = new[] { request }, AWSAccessKeyId = ConfigurationManager.AppSettings["accessKeyId"], AssociateTag = "ReplaceWithYourValue" }; // send the ItemSearch request ItemSearchResponse response = amazonClient.ItemSearch(itemSearch); // write out the results from the ItemSearch request foreach (var item in response.Items[0].Item) { Console.WriteLine(item.ItemAttributes.Title); } Console.WriteLine("done...enter any key to continue>"); Console.ReadLine(); }
static void Main(string[] args) { var ci = CultureInfo.InvariantCulture.Clone() as CultureInfo; ci.NumberFormat.NumberDecimalSeparator = "."; List <string> products = new List <string>(); List <string> price = new List <string>(); // Instantiate Amazon ProductAdvertisingAPI client AWSECommerceServicePortTypeClient amazonClient = new AWSECommerceServicePortTypeClient(); for (int i = 1; i <= 6; i++) { // prepare an ItemSearch request ItemSearchRequest request = new ItemSearchRequest(); request.SearchIndex = "All"; //request.Title = "WCF"; request.Keywords = "playstation -kindle"; request.ResponseGroup = new string[] { "ItemAttributes", "Images" }; request.ItemPage = i.ToString(); ItemSearch itemSearch = new ItemSearch(); itemSearch.Request = new ItemSearchRequest[] { request }; itemSearch.AWSAccessKeyId = ConfigurationManager.AppSettings["accessKeyId"]; itemSearch.AssociateTag = "testfo-20"; // send the ItemSearch request ItemSearchResponse response = amazonClient.ItemSearch(itemSearch); } }
public Item[] FindItems(ItemCategory category, string keywords) { var searchResult = _amazonClient.ItemSearch( new ItemSearch { AssociateTag = AmazonAssociateTag, AWSAccessKeyId = AmazonAccessKey, Request = new ItemSearchRequest[] { new ItemSearchRequest { SearchIndex = Enum.GetName(typeof(ItemCategory), category), Keywords = keywords, ItemPage = "1", ResponseGroup = new string[] { "Images", "ItemAttributes" } } } }); var items = new List <Item>(); foreach (var amazonItem in searchResult.Items[0].Item) { var item = new Item { Id = amazonItem.ASIN, ListPrice = decimal.Parse(amazonItem.ItemAttributes.ListPrice.Amount), Title = amazonItem.ItemAttributes.Title, ListingUrl = amazonItem.DetailPageURL, ImageUrl = amazonItem.SmallImage == null ? "" : amazonItem.SmallImage.URL }; items.Add(item); } return(items.ToArray()); }
static void Main(string[] args) { // Instantiate Amazon ProductAdvertisingAPI client AWSECommerceServicePortTypeClient amazonClient = new AWSECommerceServicePortTypeClient(); // prepare an ItemSearch request ItemSearchRequest request = new ItemSearchRequest { SearchIndex = "Books", Title = "WCF", ResponseGroup = new[] {"Small"} }; ItemSearch itemSearch = new ItemSearch { Request = new[] {request}, AWSAccessKeyId = ConfigurationManager.AppSettings["accessKeyId"], AssociateTag = "ReplaceWithYourValue" }; // send the ItemSearch request ItemSearchResponse response = amazonClient.ItemSearch(itemSearch); // write out the results from the ItemSearch request foreach (var item in response.Items[0].Item) { Console.WriteLine(item.ItemAttributes.Title); } Console.WriteLine("done...enter any key to continue>"); Console.ReadLine(); }
public IEnumerable<Item> GetProducts(string sona, int leht) { AWSECommerceServicePortTypeClient ecs = new AWSECommerceServicePortTypeClient(); ItemSearchRequest paring = new ItemSearchRequest(); paring.ResponseGroup = new string[] { "ItemAttributes,OfferSummary" }; paring.SearchIndex = "All"; paring.Keywords = sona; paring.ItemPage = String.Format("{0}", leht); paring.MinimumPrice = "0"; ItemSearch otsi = new ItemSearch(); otsi.Request = new ItemSearchRequest[] { paring }; otsi.AWSAccessKeyId = ConfigurationManager.AppSettings["accessKeyId"]; otsi.AssociateTag = ConfigurationManager.AppSettings["associateTag"]; ItemSearchResponse vastus = ecs.ItemSearch(otsi); if (vastus == null) { throw new Exception("Server Error - didn't get any reponse from server!"); } else if (vastus.OperationRequest.Errors != null) { throw new Exception(vastus.OperationRequest.Errors[0].Message); } else if (vastus.Items[0].Item == null) { throw new Exception("Didn't get any items!Try agen with different keyword."); } else { return vastus.Items[0].Item; } }
private static ItemSearchResponse DoAmazonItemSearch(string keywords, int page) //AWSECommerceServicePortTypeClient ecs, ItemSearchRequest request) { ItemSearchResponse response = null; // Create an ItemSearch wrapper ItemSearch search = new ItemSearch(); search.AssociateTag = _ASSOCIATE_TAG; search.AWSAccessKeyId = _ACCESS_KEY_ID; AWSECommerceServicePortTypeClient ecs = GetClient(); ItemSearchRequest request = GetSearchRequest(); request.Keywords = keywords; request.ItemPage = Convert.ToString(page); // Set the request on the search wrapper search.Request = new ItemSearchRequest[] { request }; try { //Send the request and store the response response = ecs.ItemSearch(search); } catch (NullReferenceException e) { Debug.WriteLine(e.ToString()); } return(response); }
public static void AmazonWCF() { // create a WCF Amazon ECS client BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); binding.MaxReceivedMessageSize = int.MaxValue; AWSECommerceServicePortTypeClient client = new AWSECommerceServicePortTypeClient( binding, new EndpointAddress("https://webservices.amazon.com/onca/soap?Service=AWSECommerceService")); // add authentication to the ECS client client.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(accessKeyId, secretKey)); // prepare an ItemSearch request ItemSearchRequest request = new ItemSearchRequest(); request.SearchIndex = "Electronics"; request.Title = "Monitor"; request.ResponseGroup = new string[] { "Small" }; ItemSearch itemSearch = new ItemSearch(); itemSearch.Request = new ItemSearchRequest[] { request }; itemSearch.AWSAccessKeyId = accessKeyId; //itemSearch.AssociateTag = tab // issue the ItemSearch request ItemSearchResponse response = client.ItemSearch(itemSearch); // write out the results foreach (var item in response.Items[0].Item) { Console.WriteLine(item.ItemAttributes.Title); } }
public IEnumerable <Item> GetProducts(string sona, int leht) { AWSECommerceServicePortTypeClient ecs = new AWSECommerceServicePortTypeClient(); ItemSearchRequest paring = new ItemSearchRequest(); paring.ResponseGroup = new string[] { "ItemAttributes,OfferSummary" }; paring.SearchIndex = "All"; paring.Keywords = sona; paring.ItemPage = String.Format("{0}", leht); paring.MinimumPrice = "0"; ItemSearch otsi = new ItemSearch(); otsi.Request = new ItemSearchRequest[] { paring }; otsi.AWSAccessKeyId = ConfigurationManager.AppSettings["accessKeyId"]; otsi.AssociateTag = ConfigurationManager.AppSettings["associateTag"]; ItemSearchResponse vastus = ecs.ItemSearch(otsi); if (vastus == null) { throw new Exception("Server Error - didn't get any reponse from server!"); } else if (vastus.OperationRequest.Errors != null) { throw new Exception(vastus.OperationRequest.Errors[0].Message); } else if (vastus.Items[0].Item == null) { throw new Exception("Didn't get any items!Try agen with different keyword."); } else { return(vastus.Items[0].Item); } }
public ItemSearchResponse ItemSearch(string SearchIndex, string[] Group, string Keywords) { BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); binding.MaxReceivedMessageSize = int.MaxValue; binding.MaxBufferSize = int.MaxValue; AWSECommerceServicePortTypeClient amazonClient = new AWSECommerceServicePortTypeClient( binding, new EndpointAddress("https://webservices.amazon.com/onca/soap?Service=AWSECommerceService")); // add authentication to the ECS client amazonClient.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(ConfigurationManager.AppSettings["accessKeyId"], ConfigurationManager.AppSettings["secretKey"])); ItemSearchRequest search = new ItemSearchRequest(); search.SearchIndex = SearchIndex; search.ResponseGroup = Group; search.Keywords = Keywords; ItemSearch itemSearch = new ItemSearch(); itemSearch.Request = new ItemSearchRequest[] { search }; itemSearch.AWSAccessKeyId = ConfigurationManager.AppSettings["accessKeyId"]; itemSearch.AssociateTag = ConfigurationManager.AppSettings["associateTag"]; ItemSearchResponse response = amazonClient.ItemSearch(itemSearch); return response; }
public ItemSearchResponse ItemSearch(string SearchIndex, string[] Group, string Keywords) { BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); binding.MaxReceivedMessageSize = int.MaxValue; binding.MaxBufferSize = int.MaxValue; AWSECommerceServicePortTypeClient amazonClient = new AWSECommerceServicePortTypeClient( binding, new EndpointAddress("https://webservices.amazon.com/onca/soap?Service=AWSECommerceService")); // add authentication to the ECS client amazonClient.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(ConfigurationManager.AppSettings["accessKeyId"], ConfigurationManager.AppSettings["secretKey"])); ItemSearchRequest search = new ItemSearchRequest(); search.SearchIndex = SearchIndex; search.ResponseGroup = Group; search.Keywords = Keywords; ItemSearch itemSearch = new ItemSearch(); itemSearch.Request = new ItemSearchRequest[] { search }; itemSearch.AWSAccessKeyId = ConfigurationManager.AppSettings["accessKeyId"]; itemSearch.AssociateTag = ConfigurationManager.AppSettings["associateTag"]; ItemSearchResponse response = amazonClient.ItemSearch(itemSearch); return(response); }
public List <Item> ItemSearch(string search, int page, int pagesize, out int totalpages) { var result = new List <Item>(); var amazonPage = page * pagesize / 10; while (true) { var response = client.ItemSearch( new ItemSearchRequest1(new ItemSearch() { AssociateTag = "MyTag", Request = new ItemSearchRequest[] { new ItemSearchRequest() { ResponseGroup = new string[] { "Offers", "Large", "Request" }, Keywords = search, SearchIndex = "All", ItemPage = amazonPage.ToString() }, } })); var totalResults = Convert.ToInt32(response.ItemSearchResponse.Items[0].TotalResults); { totalpages = totalResults / pagesize; if (totalResults % pagesize > 0) { totalpages++; } int i = (page - 1) * pagesize - ((amazonPage - 1) * 10); if (i < 0) { i = 0; } for (; i < response.ItemSearchResponse.Items[0].Item.Length; i++) { var item = response.ItemSearchResponse.Items[0].Item[i]; result.Add(item); if (result.Count >= pagesize) { return(result); } } if (pagesize * page >= totalResults) { return(result); } if (totalResults < pagesize) { return(result); } amazonPage++; if (amazonPage > 5) { return(result); } } } }
public ItemSearchResponse ItemSearch(SearchIndex index, string keywords, int page, List <ResponseGroup> responseGroups, Merchants merchant, int?maxPrice, int?minPrice, int?minPercentageOff) { var request = RequestBuilder(index, keywords, page, responseGroups, merchant, maxPrice, minPrice, minPercentageOff); var itemSearch = SearchRequest(request); var response = client.ItemSearch(itemSearch); return(response); }
// perform the Amazon search with SOAP and return results as a DataTable public static DataTable GetAmazonDataWithSoap() { // Create Amazon objects AWSECommerceServicePortTypeClient amazonService = new AWSECommerceServicePortTypeClient(); ItemSearch itemSearch = new ItemSearch(); ItemSearchRequest itemSearchRequest = new ItemSearchRequest(); ItemSearchResponse itemSearchResponse; // Setup Amazon objects itemSearch.AWSAccessKeyId = BalloonShopConfiguration.SubscriptionId; itemSearchRequest.Keywords = BalloonShopConfiguration.SearchKeywords; itemSearchRequest.SearchIndex = BalloonShopConfiguration.SearchIndex; itemSearchRequest.ResponseGroup = BalloonShopConfiguration.ResponseGroups.Split(','); itemSearch.Request = new ItemSearchRequest[1] { itemSearchRequest }; // Will store search results DataTable responseTable = GetResponseTable(); // If any problems occur, we prefer to send back empty result set // instead of throwing exception try { itemSearchResponse = amazonService.ItemSearch(itemSearch); Item[] results = itemSearchResponse.Items[0].Item; // Browse the results foreach (Item item in results) { // product with incomplete information will be ignored try { //create a datarow, populate it and add it to the table DataRow dataRow = responseTable.NewRow(); dataRow["ASIN"] = item.ASIN; dataRow["ProductName"] = item.ItemAttributes.Title; dataRow["ProductImageUrl"] = item.SmallImage.URL; dataRow["ProductPrice"] = item.OfferSummary.LowestNewPrice. FormattedPrice; responseTable.Rows.Add(dataRow); } catch { // Ignore products with incomplete information } } } catch (Exception e) { // ignore the error } // return the results return(responseTable); }
public DataTable GetProducts(string productName) { DataTable products = new DataTable(); products.Columns.Add("Product", typeof(string)); products.Columns.Add("Price", typeof(string)); products.Columns.Add("Image", typeof(string)); products.Columns.Add("url", typeof(string)); // Instantiate Amazon ProductAdvertisingAPI client AWSECommerceServicePortTypeClient amazonClient = new AWSECommerceServicePortTypeClient(); for (int i = 1; i <= 5; i++) { // prepare an ItemSearch request ItemSearchRequest request = new ItemSearchRequest(); request.SearchIndex = "All"; request.Keywords = productName + " -kindle"; request.ResponseGroup = new string[] { "ItemAttributes", "Images" }; request.ItemPage = i.ToString(); request.Condition = Condition.New; request.Availability = ItemSearchRequestAvailability.Available; ItemSearch itemSearch = new ItemSearch(); itemSearch.Request = new ItemSearchRequest[] { request }; itemSearch.AWSAccessKeyId = ConfigurationManager.AppSettings["accessKeyId"]; itemSearch.AssociateTag = "testfo-20"; // send the ItemSearch request ItemSearchResponse response = amazonClient.ItemSearch(itemSearch); foreach (var item in response.Items[0].Item) { try { products.Rows.Add(item.ItemAttributes.Title, item.ItemAttributes.ListPrice.FormattedPrice.Replace("$", ""), item.SmallImage.URL, item.DetailPageURL); } catch (NullReferenceException ex) { Debug.WriteLine("Caught Exception: " + ex.Message); continue; } } } return(products); }
public DataTable GetProducts(string productName) { DataTable products = new DataTable(); products.Columns.Add("Product", typeof(string)); products.Columns.Add("Price", typeof(string)); products.Columns.Add("Image", typeof(string)); products.Columns.Add("url", typeof(string)); // Instantiate Amazon ProductAdvertisingAPI client AWSECommerceServicePortTypeClient amazonClient = new AWSECommerceServicePortTypeClient(); for (int i = 1; i <= 5; i++) { // prepare an ItemSearch request ItemSearchRequest request = new ItemSearchRequest(); request.SearchIndex = "All"; request.Keywords = productName + " -kindle"; request.ResponseGroup = new string[] { "ItemAttributes", "Images"}; request.ItemPage = i.ToString(); request.Condition = Condition.New; request.Availability = ItemSearchRequestAvailability.Available; ItemSearch itemSearch = new ItemSearch(); itemSearch.Request = new ItemSearchRequest[] { request }; itemSearch.AWSAccessKeyId = ConfigurationManager.AppSettings["accessKeyId"]; itemSearch.AssociateTag = "testfo-20"; // send the ItemSearch request ItemSearchResponse response = amazonClient.ItemSearch(itemSearch); foreach (var item in response.Items[0].Item) { try { products.Rows.Add(item.ItemAttributes.Title, item.ItemAttributes.ListPrice.FormattedPrice.Replace("$", ""),item.SmallImage.URL, item.DetailPageURL); } catch (NullReferenceException ex) { Debug.WriteLine("Caught Exception: " + ex.Message); continue; } } } return products; }
public static List<System.Drawing.Image> SearchAlbumArt(string keywords) { try { keywords = CleanString(keywords); ItemSearchRequest itemRequest = new ItemSearchRequest(); itemRequest.Keywords = keywords; // http://docs.amazonwebservices.com/AWSECommerceService/2009-02-01/DG/index.html?ItemLookup.html itemRequest.SearchIndex = "Music"; // Other possibly valid choices:Classical, DigitalMusic, Mp3Downloads, Music, MusicTracks, itemRequest.ResponseGroup = new string[] { "Images" }; // images only ItemSearch request = new ItemSearch(); request.AWSAccessKeyId = Credentials.AmazonAccessKeyId; request.Request = new ItemSearchRequest[] { itemRequest }; BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); binding.MaxReceivedMessageSize = int.MaxValue; AWSECommerceServicePortTypeClient client = new AWSECommerceServicePortTypeClient(binding, new EndpointAddress("https://webservices.amazon.com/onca/soap?Service=AWSECommerceService")); client.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(Credentials.AmazonAccessKeyId, Credentials.AmazonSecretKey)); ItemSearchResponse response = client.ItemSearch(request); // Determine if book was found bool itemFound = ((response.Items[0].Item != null) && (response.Items[0].Item.Length > 0)); if (itemFound) { List<System.Drawing.Image> images = new List<System.Drawing.Image>(); foreach (Item currItem in response.Items[0].Item) { try { if (currItem != null && currItem.LargeImage != null) images.Add(ConvertByteArrayToImage(GetBytesFromUrl(currItem.LargeImage.URL))); } catch { } } return images; } } catch (Exception) {} return null; }
//returns response from Amazon search request public static ItemSearchResponse search(ItemSearchRequest request) { // create a WCF Amazon ECS client BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); binding.MaxReceivedMessageSize = int.MaxValue; AWSECommerceServicePortTypeClient client = new AWSECommerceServicePortTypeClient(binding, new EndpointAddress("https://webservices.amazon.com/onca/soap?Service=AWSECommerceService")); // add authentication to the ECS client client.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(Globals.ACCESS_KEY_ID, Globals.SECRET_KEY)); ItemSearch itemSearch = new ItemSearch(); itemSearch.Request = new ItemSearchRequest[] { request }; itemSearch.AWSAccessKeyId = Globals.ACCESS_KEY_ID; itemSearch.AssociateTag = ""; // issue the ItemSearch request return client.ItemSearch(itemSearch); }
private Items[] searchAmazonItems(String keyword, int startPage, int endPage) { List <ItemSearchRequest> itemSearchRequests = new List <ItemSearchRequest>(); ItemSearch itemSearch = new ItemSearch(); itemSearch.AWSAccessKeyId = Settings.AMAZON_ACCESS_KEY_ID; itemSearch.AssociateTag = Settings.AMAZON_ASSOCATE_TAG; // Valmistan otsingute päringud ette for (int i = startPage; i <= endPage; i++) { itemSearchRequests.Add(getItemSearchRequest(keyword, i)); } itemSearch.Request = itemSearchRequests.ToArray(); // Otsin esemeid ItemSearchResponse response = client.ItemSearch(itemSearch); return(response.Items); }
public ItemSearchResponse ItemSearch(string ItemPage, string SearchIndex, string[] ResponseGroup, string Title) { // BasicHttpBinding configuration BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); binding.MaxReceivedMessageSize = int.MaxValue; binding.MaxBufferSize = int.MaxValue; // create a WCF Amazon ECS client AWSECommerceServicePortTypeClient client = new AWSECommerceServicePortTypeClient( binding, new EndpointAddress("https://webservices.amazon.com/onca/soap?Service=AWSECommerceService")); // add authentication to the ECS client client.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(accessKeyId, secretKey)); // prepare an ItemSearchRequest ItemSearchRequest request = new ItemSearchRequest(); request.SearchIndex = SearchIndex; request.ResponseGroup = ResponseGroup; request.Title = Title; request.ItemPage = ItemPage; // prepare an ItemSearch ItemSearch search = new ItemSearch(); search.Request = new ItemSearchRequest[] { request }; search.AWSAccessKeyId = accessKeyId; search.AssociateTag = "http://affiliate-program.amazon.com/"; //get ItemSearchResponse ItemSearchResponse response = client.ItemSearch(search); return(response); }
public static Activity AmazonSearch(Activity activity, string searchTerm) { var accessKeyId = "AKIAIOXGBEXN4SPR5PYQ"; var secretKey = "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"; //var client = new AWSECommerceServicePortTypeClient(); //client.ChannelFactory.Endpoint.Behaviors.Add(new Amazon.AmazonSigningEndpointBehavior(accessKeyId, secretKey)); var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport) { MaxReceivedMessageSize = int.MaxValue }; var client = new AWSECommerceServicePortTypeClient(binding, new EndpointAddress("https://webservices.amazon.com/onca/soap?Service=AWSECommerceService")); // add authentication to the ECS client client.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(accessKeyId, secretKey)); var lookup = new ItemSearch(); var request = new ItemSearchRequest(); lookup.AssociateTag = accessKeyId; lookup.AWSAccessKeyId = secretKey; request.Keywords = searchTerm; var response = client.ItemSearch(lookup); var sb = new StringBuilder(); sb.AppendLine($"Hello {activity.From.Name} - Amazon Search results for {searchTerm}." + Environment.NewLine); var reply = activity.CreateReply(sb.ToString()); reply.Type = "message"; return(reply); }
static void Main(string[] args) { // Instantiate Amazon ProductAdvertisingAPI client BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); binding.MaxReceivedMessageSize = int.MaxValue; AWSECommerceServicePortTypeClient amazonClient = new AWSECommerceServicePortTypeClient( binding, new EndpointAddress("https://webservices.amazon.com/onca/soap?Service=AWSECommerceService")); //Adding this uses the code in Amazon.PAAPI.WCF to sign requests automagically amazonClient.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior()); // prepare an ItemSearch request ItemSearchRequest request = new ItemSearchRequest(); request.SearchIndex = "DVD"; request.Title = "Matrix"; request.ResponseGroup = new string[] { "Small" }; ItemSearch itemSearch = new ItemSearch(); itemSearch.Request = new ItemSearchRequest[] { request }; itemSearch.AssociateTag = "notag"; //this is a required param, so I just use a dummy value which seems to work // send the ItemSearch request ItemSearchResponse response = amazonClient.ItemSearch(itemSearch); // write out the results from the ItemSearch request foreach (var item in response.Items[0].Item) { Console.WriteLine(item.ItemAttributes.Title); } Console.WriteLine("\n\n<<< done...enter any key to continue >>>"); Console.ReadLine(); }
public bool SearchForMovie(string movieName, int maxResults) { _locale = AmazonLocale.FromString(Properties.Settings.Default.AmazonLocale); BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); binding.MaxReceivedMessageSize = int.MaxValue; client = new AWSECommerceServicePortTypeClient( binding, new EndpointAddress(_locale.URL) ); client.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior()); try { ItemSearchRequest req = new ItemSearchRequest(); req.SearchIndex = Properties.Settings.Default.AmazonSearchMode; req.Title = movieName; req.ItemPage = @"1"; req.ResponseGroup = new string[] { "Medium", "Subjects" }; ItemSearch iSearch = new ItemSearch(); iSearch.Request = new ItemSearchRequest[] { req }; iSearch.AWSAccessKeyId = Properties.Settings.Default.AWEAccessKeyId; ItemSearchResponse res = client.ItemSearch(iSearch); if (res.Items[0].Item.Length > 0) { Item[] amazonItems = res.Items[0].Item; int itemsToProcess = Math.Min(amazonItems.Length, maxResults); if (amazonItems != null) { // convert Amazon Items to generic collection of DVDs OMLSDKTitle[] searchResults = new OMLSDKTitle[itemsToProcess]; for (int i = 0; i < itemsToProcess; i++) { searchResults[i] = AmazonToOML.TitleFromAmazonItem(amazonItems[i]); } int totalPages = 0; int totalItems = 0; if (res.Items[0].TotalPages != null) { totalPages = Convert.ToInt32(res.Items[0].TotalPages); } if (res.Items[0].TotalResults != null) { totalItems = Convert.ToInt32(res.Items[0].TotalResults); } _searchResult = (new AmazonSearchResult(searchResults, totalPages, totalItems)); } else { _searchResult = (new AmazonSearchResult(null, 0, 0)); } return(true); } } catch { _searchResult = (new AmazonSearchResult(null, 0, 0)); } return(false); }
public ItemSearchResponse SearchItem(ItemSearchRequest itemSearchRequest, string[] responseGroup) { itemSearchRequest.ResponseGroup = responseGroup; ItemSearch itemSearch = new ItemSearch(); itemSearch.Request = new ItemSearchRequest[] { itemSearchRequest }; itemSearch.AWSAccessKeyId = AccessKeyId; itemSearch.AssociateTag = AssociateTag; using (AWSECommerceServicePortTypeClient client = new AWSECommerceServicePortTypeClient(_BasicHttpBinding, _EndPointAddress)) { client.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(AccessKeyId, SecretKey)); return client.ItemSearch(itemSearch); } }
public Dictionary <string, string> GetProdDetails(string pName) { Dictionary <string, string> proddescDic = new Dictionary <string, string>(); string title = ""; string manufacturer = ""; string model = ""; string brand = ""; string priceInDollar = ""; double price = 0.0; string[] features; string fea = ""; // Instantiate Amazon ProductAdvertisingAPI client AWSECommerceServicePortTypeClient amazonClient = new AWSECommerceServicePortTypeClient(); // prepare an ItemSearch request ItemSearchRequest request = new ItemSearchRequest(); request.SearchIndex = "All"; //request.Title = "WCF"; request.Keywords = pName; request.ResponseGroup = new string[] { "ItemAttributes", "Offers", "OfferSummary", "Reviews" }; ItemSearch itemSearch = new ItemSearch(); itemSearch.Request = new ItemSearchRequest[] { request }; itemSearch.AWSAccessKeyId = ConfigurationManager.AppSettings["accessKeyId"]; itemSearch.AssociateTag = "newmobiles0d-20"; // send the ItemSearch request try { bool getNextTitle = false; ItemSearchResponse response = amazonClient.ItemSearch(itemSearch); foreach (var item in response.Items[0].Item) { if (!IsCorrect) { //Getting title try { title = item.ItemAttributes.Title; if (!(title.ToLower().Contains("Stick".ToLower())) || (title.ToLower().Contains("Case".ToLower())) || (title.ToLower().Contains("Cover".ToLower()))) { proddescDic["Title"] = title; IsCorrect = true; getNextTitle = false; } else { getNextTitle = true; proddescDic["Title"] = title; } } catch (Exception) { }; if (!getNextTitle) { //Getting manufacturer of the item try { manufacturer = item.ItemAttributes.Manufacturer; proddescDic["Manufacturer"] = manufacturer; } catch (Exception) { }; //Getting model try { model = item.ItemAttributes.Model; proddescDic["Model"] = model; } catch (Exception) { }; //Getting Brand try { brand = item.ItemAttributes.Brand; proddescDic["Brand"] = brand; } catch (Exception) { }; //Getting Amount in Dollar try { priceInDollar = item.ItemAttributes.ListPrice.FormattedPrice; proddescDic["Price"] = priceInDollar; } catch (Exception) { }; //Getting Amount try { string p = item.ItemAttributes.ListPrice.Amount; } catch (Exception) { }; try { features = item.ItemAttributes.Feature; foreach (var f in features) { fea = fea + "\n" + f; } proddescDic["Features"] = fea; Console.WriteLine(fea); } catch (Exception) { }; } } if ((item.CustomerReviews.HasReviews) == true) { string str = item.CustomerReviews.IFrameURL; string final_response = ""; try { //Getting html from IFrame URL HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(str); req.Method = "POST"; HttpWebResponse res = (HttpWebResponse)req.GetResponse(); StreamReader stream = new StreamReader(res.GetResponseStream()); final_response = stream.ReadToEnd(); GetMainPageHtml(final_response); } catch (Exception e) { Console.WriteLine(e); } } } } catch (Exception e1) { } return(proddescDic); }
static void Main(String[] args) { // Write to console Console.WriteLine("Welcome to the C# Station Tutorial!"); // Set default args if two are not supplied if (args.Length != 2) { args = new string[] { "DVD", "Matrix" }; } // Get searchIndex and keywords from the command line string searchIndex = args[0]; string keywords = args[1]; // Create an instance of the Product Advertising API service AWSECommerceServicePortTypeClient ecs = new AWSECommerceServicePortTypeClient(); /* Error: * An endpoint configuration section for contract 'amazon.ecs.AWSECommerceServicePortType' * could not be loaded because more than one endpoint configuration for that contract was * found. Please indicate the preferred endpoint configuration section by name. */ // Create ItemSearch wrapper ItemSearch search = new ItemSearch(); //search.AssociateTag = assocTag; search.AWSAccessKeyId = accessKeyId; // Create a request object ItemSearchRequest request = new ItemSearchRequest(); // Fill request object with request parameters request.ResponseGroup = new string[] { "ItemAttributes" }; // Set SearchIndex and Keywords request.SearchIndex = searchIndex; request.Keywords = keywords; // Set the request on the search wrapper search.Request = new ItemSearchRequest[] { request }; Console.WriteLine(request.Keywords); try { //Send the request and store the response in response Console.WriteLine("try..."); ItemSearchResponse response = ecs.ItemSearch(search); //Check for null response if (response == null) { throw new Exception("Server Error - no response recieved!"); } //ItemSearchResult[] itemsArray = response.GetItemSearchResult; if (response.OperationRequest.Errors != null) { throw new Exception(response.OperationRequest.Errors[0].Message); } Console.WriteLine("Response: " + response.ToString()); Console.WriteLine("Length: " + response.Items.Length); } catch (Exception e) { Console.WriteLine("...catch"); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Err: " + e.Message); Console.WriteLine("Type: " + e.GetType()); Console.WriteLine("Inner Exception: " + e.InnerException.Message); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Press any key to quit..."); // http://www.webdesigncompany.co.uk/blog/2011/10/5/using-the-new-amazon-product-api-wsdl-with-microsoftwebservices3/ // Err: The remote server returned an unexpected response: (400) Bad Request. } Console.ReadKey(); }
// the program starts here static void Main(string[] args) { // create a WCF Amazon ECS client BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); binding.MaxReceivedMessageSize = int.MaxValue; AWSECommerceServicePortTypeClient client = new AWSECommerceServicePortTypeClient( binding, new EndpointAddress("https://webservices.amazon.com/onca/soap?Service=AWSECommerceService")); // add authentication to the ECS client client.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(accessKeyId, secretKey)); ItemLookupRequest request2 = new ItemLookupRequest(); request2.ItemId = new String[] { "2817801997" }; request2.IdType = ItemLookupRequestIdType.ISBN; request2.ResponseGroup = new String[] { "Medium" }; request2.IdTypeSpecified = true; request2.SearchIndex = "Books"; ItemLookup itemLookup = new ItemLookup(); itemLookup.Request = new ItemLookupRequest[] { request2 }; itemLookup.AWSAccessKeyId = accessKeyId; itemLookup.AssociateTag = "213"; ItemLookupResponse response2 = client.ItemLookup(itemLookup); foreach (var item in response2.Items[0].Item) { // Create a web request to the URL for the picture System.Net.WebRequest webRequest = HttpWebRequest.Create(item.MediumImage.URL); // Execute the request synchronuously HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse(); // Create an image from the stream returned by the web request //pCover.Image = new System.Drawing.Bitmap(webResponse.GetResponseStream()); // Finally, close the request webResponse.Close(); Console.WriteLine(item.ItemAttributes.Title); } // prepare an ItemSearch request ItemSearchRequest request = new ItemSearchRequest(); request.SearchIndex = "Books"; request.Title = "Node.js"; request.ResponseGroup = new string[] { "Small" }; ItemSearch itemSearch = new ItemSearch(); itemSearch.Request = new ItemSearchRequest[] { request }; //itemSearch.AssociateTag = "testsite09f-21"; itemSearch.AssociateTag = "213"; itemSearch.AWSAccessKeyId = accessKeyId; // issue the ItemSearch request ItemSearchResponse response = client.ItemSearch(itemSearch); // write out the results foreach (var item in response.Items[0].Item) { Console.WriteLine(item.ItemAttributes.Title); } Console.ReadLine(); }
public async Task<SongData> getData(SongData newSong, string fullRequest) { try { // Instantiate Amazon ProductAdvertisingAPI client BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); binding.MaxReceivedMessageSize = int.MaxValue; AWSECommerceServicePortTypeClient amazonClient = new AWSECommerceServicePortTypeClient( binding, new EndpointAddress("https://webservices.amazon.com/onca/soap?Service=AWSECommerceService")); // add authentication to the ECS client amazonClient.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(accessKeyId, secretKey)); // prepare an ItemSearch request ItemSearchRequest request = new ItemSearchRequest(); request.SearchIndex = "MP3Downloads"; request.RelationshipType = new string[] { "Tracks" }; request.ResponseGroup = new string[] { "ItemAttributes", "Images", "Offers", "RelatedItems" }; request.Keywords = fullRequest; ItemSearch itemSearch = new ItemSearch(); itemSearch.Request = new ItemSearchRequest[] { request }; itemSearch.AWSAccessKeyId = accessKeyId; itemSearch.AssociateTag = "1330-3170-0573"; // send the ItemSearch request ItemSearchResponse response = amazonClient.ItemSearch(itemSearch); var item = response.Items[0].Item[0]; //<ProductTypeName>DOWNLOADABLE_MUSIC_TRACK</ProductTypeName> if (response.Items[0].Item[0].ItemAttributes.ProductTypeName == "DOWNLOADABLE_MUSIC_ALBUM") { item = response.Items[0].Item[1]; } // if no response to search if (item == null) { try { // Try new search and remove the album newSong.Album = "UNKNOWN"; // Re-iterate over the search method await getData(newSong, fullRequest); } catch { // Removing the album produced no results // Continue forward... } } // Get year from full Release Date var var formatYear = DateTime.Parse(item.ItemAttributes.ReleaseDate).Year; newSong.UserID = 1; newSong.LocationID = 1; newSong.Album = item.RelatedItems[0].RelatedItem[0].Item.ItemAttributes.Title; newSong.Artist = item.ItemAttributes.Creator[0].Value; newSong.Title = item.ItemAttributes.Title; newSong.Year = (int)formatYear; newSong.Genre = item.ItemAttributes.Genre; newSong.FilePath = ""; newSong.Duration = (int)item.ItemAttributes.RunningTime.Value; newSong.Price = item.Offers.Offer[0].OfferListing[0].Price.FormattedPrice; newSong.ASIN = item.ASIN; newSong.Artwork = item.LargeImage.URL; return newSong; } catch { return newSong; } }
public static ProductsPages ItemSearchRequestResult(string title, int webPage, int itemPerPage) { BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); binding.MaxReceivedMessageSize = int.MaxValue; binding.MaxBufferSize = int.MaxValue; // create a WCF Amazon ECS client AWSECommerceServicePortTypeClient client = new AWSECommerceServicePortTypeClient( binding, new EndpointAddress("https://webservices.amazon.com/onca/soap?Service=AWSECommerceService")); // add authentication to the ECS client client.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(accessKeyId, secretKey)); // prepare an ItemSearch request ItemSearchRequest searchRequest = new ItemSearchRequest(); searchRequest.SearchIndex = "Books"; searchRequest.Title = title; searchRequest.ResponseGroup = new string[] { "ItemAttributes", "Offers" }; ItemSearch itemSearch = new ItemSearch(); itemSearch.Request = new ItemSearchRequest[] { searchRequest }; itemSearch.AWSAccessKeyId = accessKeyId; itemSearch.AssociateTag = "http://affiliate-program.amazon.com/"; int skip = (webPage - 1) * itemPerPage; int startPage; if ((skip % 10) <= 2 && (skip % 10) != 0) { startPage = webPage + 1; } else { startPage = webPage; } int startItem = skip % 10; ProductsPages productPages = new ProductsPages(); for (int page = startPage; page <= 10; page++) { searchRequest.ItemPage = Convert.ToString(page); ItemSearchResponse searchResponse = client.ItemSearch(itemSearch); int totalPages = Convert.ToInt32(searchResponse.Items[0].TotalPages); if (totalPages < 10) { productPages.Pages = totalPages; } else { productPages.Pages = 10; } if (searchResponse.Items[0].Item != null) { for (int i = startItem; i < searchResponse.Items[0].Item.Length; i++) { if (itemPerPage > 0) { var item = searchResponse.Items[0].Item[i]; Debug.WriteLine("{0}\t{1}\tpage:{2}\titem:{3}", item.ItemAttributes.Title, Convert.ToDecimal(item.OfferSummary.LowestNewPrice.Amount) / 100, page, i); Product currentProduct = new Product() { Title = item.ItemAttributes.Title, Price = Convert.ToDecimal(item.OfferSummary.LowestNewPrice.Amount) / 100 }; productPages.Products.Add(currentProduct); itemPerPage--; } else { break; } } startItem = 0; Thread.Sleep(1000); //Amazon can ask requests only once per second } } return(productPages); }
/// <summary> /// Performs the search. /// </summary> private void PerformSearch() { if (this.txtSearchCriteria.Text.Length == 0) { return; } try { // create a WCF Amazon ECS client var basicBinding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); basicBinding.MaxReceivedMessageSize = 2147483647; basicBinding.ReaderQuotas.MaxStringContentLength = int.MaxValue; var client = new AWSECommerceServicePortTypeClient( basicBinding, new EndpointAddress("https://webservices.amazon.com/onca/soap?Service=AWSECommerceService")); // add authentication to the ECS client client.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(AmazonID, AmazonKey)); var request = new ItemSearchRequest(); request.Availability = ItemSearchRequestAvailability.Available; request.Condition = Condition.All; request.ItemPage = this.pageNumber.ToString(); request.MerchantId = "Amazon"; request.ResponseGroup = new[] { "Medium", "Reviews", "ItemAttributes", "BrowseNodes" }; request.SearchIndex = "DVD"; request.Title = this.txtSearchCriteria.Text; var itemSearch = new ItemSearch(); itemSearch.Request = new[] { request }; itemSearch.AWSAccessKeyId = AmazonID; ItemSearchResponse response = client.ItemSearch(itemSearch); if (response.Items[0].Item != null) { this.lbResults.Items.Clear(); foreach (Items resultItem in response.Items) { foreach (Item displayItem in resultItem.Item) { ItemAttributes item = displayItem.ItemAttributes; // Work out which review (if any) we can use string myReview; if (displayItem.EditorialReviews == null) { if (displayItem.CustomerReviews == null) { myReview = string.Empty; } else { myReview = this.orNull(displayItem.CustomerReviews.Review[0].Content); } } else { myReview = this.orNull(displayItem.EditorialReviews[0].Content); } var _entry = new AmazonEntry( this.orNull(displayItem.ASIN), this.orNull(item.Title), item.Director == null ? string.Empty : this.orNull(item.Director[0]), this.orNull(item.TheatricalReleaseDate), myReview, this.orNull(displayItem.DetailPageURL), this.orNull(GetGenre(displayItem)), this.orNull(item.AudienceRating), displayItem.MediumImage == null ? string.Empty : this.orNull(displayItem.MediumImage.URL)); this.lbResults.Items.Add(_entry); } } this.lblPage.Text = "Page " + this.pageNumber.ToString(); this.safePageNumber = this.pageNumber; } else { this.pageNumber = this.safePageNumber; } this.AddLogEntry("Search Complete", LogType.Info); } catch (Exception ex) { this.pageNumber = this.safePageNumber; this.AddLogEntry(ex.Message, LogType.Fail); } }
// perform the Amazon search with SOAP and return results as a DataTable public static DataTable GetAmazonDataWithSoap() { // Create Amazon objects AWSECommerceServicePortTypeClient amazonService = new AWSECommerceServicePortTypeClient(); ItemSearch itemSearch = new ItemSearch(); ItemSearchRequest itemSearchRequest = new ItemSearchRequest(); ItemSearchResponse itemSearchResponse; // Setup Amazon objects itemSearch.AWSAccessKeyId = BalloonShopConfiguration.SubscriptionId; itemSearchRequest.Keywords = BalloonShopConfiguration.SearchKeywords; itemSearchRequest.SearchIndex = BalloonShopConfiguration.SearchIndex; itemSearchRequest.ResponseGroup = BalloonShopConfiguration.ResponseGroups.Split(','); itemSearch.Request = new ItemSearchRequest[1] { itemSearchRequest }; // Will store search results DataTable responseTable = GetResponseTable(); // If any problems occur, we prefer to send back empty result set // instead of throwing exception try { itemSearchResponse = amazonService.ItemSearch(itemSearch); Item[] results = itemSearchResponse.Items[0].Item; // Browse the results foreach (Item item in results) { // product with incomplete information will be ignored try { //create a datarow, populate it and add it to the table DataRow dataRow = responseTable.NewRow(); dataRow["ASIN"] = item.ASIN; dataRow["ProductName"] = item.ItemAttributes.Title; dataRow["ProductImageUrl"] = item.SmallImage.URL; dataRow["ProductPrice"] = item.OfferSummary.LowestNewPrice. FormattedPrice; responseTable.Rows.Add(dataRow); } catch { // Ignore products with incomplete information } } } catch (Exception e) { // ignore the error } // return the results return responseTable; }
public static void GetCDCover(CD cd) { try { if (cd == null) { return; } Cursor.Current = Cursors.WaitCursor; string filenameFront = cd.GetCDCoverFilename(CoverType.Front); string filenameBack = cd.GetCDCoverFilename(CoverType.Back); AWSECommerceServicePortTypeClient amazonClient = new AWSECommerceServicePortTypeClient(); ItemSearch itemSearch = new ItemSearch(); itemSearch.AWSAccessKeyId = "0FN016GTSMZHJD0C7YG2"; ItemSearchRequest itemSearchRequest = new ItemSearchRequest(); itemSearchRequest.Artist = cd.Artist; itemSearchRequest.Keywords = cd.Title; itemSearchRequest.SearchIndex = "Music"; itemSearchRequest.Sort = "salesrank"; itemSearchRequest.ResponseGroup = new string[] { "Images" }; itemSearchRequest.ItemPage = "1"; itemSearch.Request = new ItemSearchRequest[1] { itemSearchRequest }; itemSearch.AssociateTag = "hitbase-21"; ItemSearchResponse itemSearchResponse = null; bool nothingFound = false; try { itemSearchResponse = amazonClient.ItemSearch(itemSearch); } catch { nothingFound = true; } try { if (!nothingFound && itemSearchResponse != null && itemSearchResponse.Items != null && itemSearchResponse.Items.Length > 0 && itemSearchResponse.Items[0].Item != null && itemSearchResponse.Items[0].Item.Length > 0) { WebClient webclient = new WebClient(); webclient.UseDefaultCredentials = true; webclient.Proxy.Credentials = CredentialCache.DefaultCredentials; Item item = itemSearchResponse.Items[0].Item[0]; if (item.LargeImage != null && !string.IsNullOrEmpty(item.LargeImage.URL)) { webclient.DownloadFile(item.LargeImage.URL, filenameFront); } else if (item.MediumImage != null && !string.IsNullOrEmpty(item.MediumImage.URL)) { webclient.DownloadFile(item.MediumImage.URL, filenameFront); } else if (item.SmallImage != null && !string.IsNullOrEmpty(item.SmallImage.URL)) { webclient.DownloadFile(item.SmallImage.URL, filenameFront); } if (item.ImageSets != null && item.ImageSets.Length > 0) { foreach (ImageSet imageSet in item.ImageSets) { //foreach (ImageSet imageSet in imgSet) { if (imageSet.Category == "variant") { if (imageSet.LargeImage != null) { webclient.DownloadFile(imageSet.LargeImage.URL, filenameBack); } else if (imageSet.MediumImage != null) { webclient.DownloadFile(imageSet.MediumImage.URL, filenameBack); } else if (imageSet.SmallImage != null) { webclient.DownloadFile(imageSet.SmallImage.URL, filenameBack); } } } } } } } catch (Exception e) { FormUnhandledException formUnhandledException = new FormUnhandledException(e); formUnhandledException.ShowDialog(); } if (File.Exists(filenameFront)) { cd.CDCoverFrontFilename = filenameFront; } if (File.Exists(filenameBack)) { cd.CDCoverBackFilename = filenameBack; } } finally { Cursor.Current = Cursors.Default; } }
private const string assocTag = ""; /*!< This is the associate tag for the connection */ //! This is the method that defines a search and sends a request to Amazon /** * It contains code obtained from the "Product Advertising API Getting * Started Guide API Version 2011-08-01" found at * http://aws.amazon.com/archives/Product-Advertising-API/. */ public static void SendRequest() { // Get searchIndex and keywords from the command line string searchIndex = "DVD"; string keywords = "Matrix"; // Create an instance of the Product Advertising API service AWSECommerceServicePortTypeClient ecs = new AWSECommerceServicePortTypeClient(); /* Error: * An endpoint configuration section for contract 'amazon.ecs.AWSECommerceServicePortType' * could not be loaded because more than one endpoint configuration for that contract was * found. Please indicate the preferred endpoint configuration section by name. */ // Create ItemSearch wrapper ItemSearch search = new ItemSearch(); //search.AssociateTag = assocTag; search.AWSAccessKeyId = accessKeyId; // Create a request object ItemSearchRequest request = new ItemSearchRequest(); // Fill request object with request parameters request.ResponseGroup = new string[] { "ItemAttributes" }; // Set SearchIndex and Keywords request.SearchIndex = searchIndex; request.Keywords = keywords; // Set the request on the search wrapper search.Request = new ItemSearchRequest[] { request }; Console.WriteLine(request.Keywords); try { //Send the request and store the response in response Console.WriteLine("try..."); //ItemLookup itemLookup = new ItemLookup(); //ItemLookupRequest itemLookupRequest = new ItemLookupRequest(); //itemLookupRequest.SearchIndex = "DVD"; //itemLookupRequest.ItemId = new string[] { "B005OCFGTO" }; //itemLookupRequest.ResponseGroup = new string[] { "ItemAttributes" }; //itemLookup.Request = new ItemLookupRequest[] { itemLookupRequest }; //itemLookup.AWSAccessKeyId = accessKeyId; //ItemLookupResponse response = ecs.ItemLookup(itemLookup); ItemSearchResponse response = ecs.ItemSearch(search); //Check for null response if (response == null) { throw new Exception("Server Error - no response recieved!"); } //ItemSearchResult[] itemsArray = response.GetItemSearchResult; if (response.OperationRequest.Errors != null) { throw new Exception(response.OperationRequest.Errors[0].Message); } Console.WriteLine("Response: " + response.ToString()); Console.WriteLine("Length: " + response.Items.Length); } catch (Exception e) { Console.WriteLine("...catch"); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Err: " + e.Message); Console.WriteLine("Type: " + e.GetType()); Console.WriteLine("Inner Exception: " + e.InnerException.Message); Console.ForegroundColor = ConsoleColor.White; // http://www.webdesigncompany.co.uk/blog/2011/10/5/using-the-new-amazon-product-api-wsdl-with-microsoftwebservices3/ // Err: The remote server returned an unexpected response: (400) Bad Request. /* * ==Error== ==Description== * IncompleteSignature The request signature does not conform to AWS standards. * * InvalidAction The action or operation requested is invalid. * * InvalidParameterCombination Parameters that must not be used together were used together. * * InvalidParameterValue A bad or out-of-range value was supplied for the input parameter. * * InvalidQueryParameter AWS query string is malformed, does not adhere to AWS standards. * * MissingAction The request is missing an action or operation parameter. * * MissingParameter An input parameter that is mandatory for processing the * request is not supplied. * * RequestExpired Request is past expires date or the request date * (either with 15 minute padding), or the request date * occurs more than 15 minutes in the future. * * Throttling Request was denied due to request throttling. */ } Console.WriteLine("Press any key to quit..."); //Console.ReadKey(); }
//geting products for sending mail to the user public Dictionary <string, string> GetProductAgainstHashTag(string prodName) { Dictionary <string, string> proddescDic = new Dictionary <string, string>(); string title = ""; string manufacturer = ""; string model = ""; string brand = ""; string priceInDollar = ""; double price = 0.0; string[] features; // Instantiate Amazon ProductAdvertisingAPI client AWSECommerceServicePortTypeClient amazonClient = new AWSECommerceServicePortTypeClient(); BasicHttpBinding httpBinding = new BasicHttpBinding(); httpBinding.Name = "AWSECommerceServiceBindingNoTransport"; httpBinding.MaxReceivedMessageSize = 2147483647; httpBinding.MaxBufferSize = 2147483647; // prepare an ItemSearch request ItemSearchRequest request = new ItemSearchRequest(); //request.SearchIndex = "Electronics"; request.SearchIndex = "All"; //request.Title = "WCF"; request.Keywords = prodName; request.ResponseGroup = new string[] { "ItemAttributes", "Offers", "OfferSummary", "Reviews" }; ItemSearch itemSearch = new ItemSearch(); itemSearch.Request = new ItemSearchRequest[] { request }; itemSearch.AWSAccessKeyId = ConfigurationManager.AppSettings["accessKeyId"]; itemSearch.AssociateTag = "newmobiles0d-20"; // send the ItemSearch request try { ItemSearchResponse response = amazonClient.ItemSearch(itemSearch); foreach (var item in response.Items[0].Item) { if (!GetReview) { //Getting title try { title = item.ItemAttributes.Title; proddescDic["Title"] = title; if (!(title.Equals(""))) { GetReview = true; } } catch (Exception) { }; //Getting manufacturer of the item try { manufacturer = item.ItemAttributes.Manufacturer; proddescDic["Manufacturer"] = manufacturer; } catch (Exception) { }; //Getting model try { model = item.ItemAttributes.Model; proddescDic["Model"] = model; } catch (Exception) { }; //Getting Brand try { brand = item.ItemAttributes.Brand; proddescDic["Brand"] = brand; } catch (Exception) { }; //Getting Amount in Dollar try { priceInDollar = item.ItemAttributes.ListPrice.FormattedPrice; proddescDic["Price"] = priceInDollar; } catch (Exception) { }; //Getting Amount try { price = int.Parse(item.ItemAttributes.ListPrice.Amount); } catch (Exception) { }; try { features = item.ItemAttributes.Feature; string fea = ""; foreach (var f in features) { fea = fea + "\n" + f; } proddescDic["Features"] = fea; } catch (Exception) { }; } if (reviewLoopIterator < 5) { if ((item.CustomerReviews.HasReviews) == true) { reviewLoopIterator++; string str = item.CustomerReviews.IFrameURL; string final_response = ""; try { //Getting html from IFrame URL HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(str); req.Method = "POST"; HttpWebResponse res = (HttpWebResponse)req.GetResponse(); StreamReader stream = new StreamReader(res.GetResponseStream()); final_response = stream.ReadToEnd(); GetMainPageHtml(final_response); } catch (Exception e) { Console.WriteLine(e); } } } else { break; } } return(proddescDic); } catch (Exception e1) { return(proddescDic); } }
public override bool GetResults(string keywords, string imdbID, bool skipImages) { bool _result = false; // create a WCF Amazon ECS client BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); binding.MaxReceivedMessageSize = int.MaxValue; AWSECommerceServicePortTypeClient client = new AWSECommerceServicePortTypeClient( binding, new EndpointAddress(TargetUrl)); // add authentication to the ECS client client.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(accessKeyId, secretKey)); // prepare an ItemSearch request ItemSearchRequest request = new ItemSearchRequest(); //request.Count = "1"; request.Condition = ThumbGen.Amazon.ECS.Condition.All; request.SearchIndex = this.SearchIndex; //request.Title = title; request.Keywords = keywords;//title.Replace(" ", "%20"); request.ResponseGroup = new string[] { "Small", "Images" }; ItemSearch itemSearch = new ItemSearch(); itemSearch.Request = new ItemSearchRequest[] { request }; itemSearch.AWSAccessKeyId = accessKeyId; itemSearch.AssociateTag = associatedTag; // issue the ItemSearch request ItemSearchResponse response = null; try { response = client.ItemSearch(itemSearch); } catch { return(_result); } if (response == null) { response = client.ItemSearch(itemSearch); } if (response != null) { // prepare the ResultsList if (response.Items[0] != null && response.Items[0].Item != null) { foreach (Item item in response.Items[0].Item) { if (FileManager.CancellationPending) { return(ResultsList.Count != 0); } string _imageUrl = item.LargeImage == null ? string.Empty : item.LargeImage.URL; if (!string.IsNullOrEmpty(_imageUrl)) { ResultMovieItem _movieItem = new ResultMovieItem(null, item.ItemAttributes.Title, _imageUrl, CollectorName); _movieItem.MovieInfo = GetMovieInfo(item); ResultsList.Add(_movieItem); } } _result = true; } } return(_result); }
public static Collection <PartialMatche> Search(string search, string artist, AmazonIndex index, AmazonCountry country, AmazonBrowserNode node) { ItemSearch service = new ItemSearch(); ItemSearchRequest request = new ItemSearchRequest(); request.Title = search.Trim(); request.SearchIndex = index.ToString(); if (string.IsNullOrWhiteSpace(artist) == false) { if (index == AmazonIndex.Books) { request.Author = artist; } else { request.Artist = artist; } } request.Sort = "salesrank"; if (node != AmazonBrowserNode.None) { request.BrowseNode = Enum.Format(typeof(AmazonBrowserNode), node, "d"); } switch (index) { case AmazonIndex.VideoGames: request.ResponseGroup = new [] { "Medium", "Images" }; break; default: request.ResponseGroup = new [] { "Small", "Images" }; break; } service.Request = new [] { request }; service.AWSAccessKeyId = Aws1; service.AssociateTag = AssociateTag; AWSECommerceServicePortTypeClient client = new AWSECommerceServicePortTypeClient( new BasicHttpBinding("AWSECommerceServiceBinding"), new EndpointAddress(string.Format("https://webservices.amazon.{0}/onca/soap?Service=AWSECommerceService", country.ToString()))); // add authentication to the ECS client client.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(Aws1, Aws2)); ItemSearchResponse response = client.ItemSearch(service); if (response.Items.GetLength(0) > 0) { if (response.Items[0].Item != null) { return(CreatePartialMatch(response.Items[0].Item, index)); } else { return(null); } } else { return(null); } }
private static void GetArtistCredits(Artist artist, AmazonIndex index, AmazonCountry country, int pageIndex) { ItemSearch itemsearch = new ItemSearch(); ItemSearchRequest request = new ItemSearchRequest(); request.SearchIndex = index.ToString(); request.ItemPage = pageIndex.ToString(CultureInfo.InvariantCulture); EntityType entityType = EntityType.Music; switch (index) { case AmazonIndex.Books: request.Author = artist.FulleName; entityType = EntityType.Books; break; case AmazonIndex.Music: request.Artist = artist.FulleName; entityType = EntityType.Music; break; } request.ResponseGroup = new [] { "Small" }; itemsearch.Request = new [] { request }; itemsearch.AWSAccessKeyId = Aws1; itemsearch.AssociateTag = AssociateTag; AWSECommerceServicePortTypeClient client = new AWSECommerceServicePortTypeClient( new BasicHttpBinding("AWSECommerceServiceBinding"), new EndpointAddress(string.Format("https://webservices.amazon.{0}/onca/soap?Service=AWSECommerceService", country.ToString()))); // add authentication to the ECS client client.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(Aws1, Aws2)); try { ItemSearchResponse response = client.ItemSearch(itemsearch); if (response.Items.GetLength(0) > 0) { if (response.Items[0].Item != null) { foreach (Item item in response.Items[0].Item) { if (artist.ArtistCredits.Any(c => c.Title.ToUpperInvariant() == item.ItemAttributes.Title.ToUpperInvariant()) == false) { ArtistCredits credit = new ArtistCredits(); credit.Title = item.ItemAttributes.Title; #region Released if (string.IsNullOrWhiteSpace(item.ItemAttributes.ReleaseDate) == false) { DateTime date; if (DateTime.TryParse(item.ItemAttributes.ReleaseDate, out date) == true) { credit.ReleaseDate = date; } } else if (string.IsNullOrWhiteSpace(item.ItemAttributes.PublicationDate) == false) { DateTime date; if (DateTime.TryParse(item.ItemAttributes.PublicationDate, out date) == true) { credit.ReleaseDate = date; } } #endregion credit.EntityType = entityType; // credit.BuyLink = item.DetailPageURL; // credit.BuyLink = string.Format(@"http://www.amazon.{0}/gp/aws/cart/add.html?ASIN.1={1}&AWSAccessKeyId={2}&AssociateTag={3}", // country.ToString(), item.ASIN, Aws1,AssociateTag); credit.BuyLink = string.Format(@"http://www.amazon.{0}/exec/obidos/ASIN/{1}/{2}/", country, item.ASIN, AssociateTag); #region Description if (item.EditorialReviews != null) { string description = string.Empty; foreach (EditorialReview edito in item.EditorialReviews) { if (edito.Content.Length > description.Length && edito.IsLinkSuppressed == false) { description = edito.Content; break; } } credit.Notes = Util.PurgeHtml(description); } #endregion artist.ArtistCredits.Add(credit); } } int totalpage; if (int.TryParse(response.Items[0].TotalPages, out totalpage)) { if (pageIndex < totalpage) { pageIndex++; GetArtistCredits(artist, index, country, pageIndex); } } } } } catch (ServerTooBusyException) { } }
public void GetReviews() { // Instantiate Amazon ProductAdvertisingAPI client AWSECommerceServicePortTypeClient amazonClient = new AWSECommerceServicePortTypeClient(); DbWrappers wrapper = new DbWrappers(); List <Product> list = wrapper.GetAllProducts(); foreach (var prod in list) { if (hasReviews == true) { hasReviews = false; } // prepare an ItemSearch request ItemSearchRequest request = new ItemSearchRequest(); request.SearchIndex = "Electronics"; //request.Title = "WCF"; request.Keywords = prod.Title; request.ResponseGroup = new string[] { "ItemAttributes", "Offers", "OfferSummary", "Reviews" }; ItemSearch itemSearch = new ItemSearch(); itemSearch.Request = new ItemSearchRequest[] { request }; itemSearch.AWSAccessKeyId = ConfigurationManager.AppSettings["accessKeyId"]; itemSearch.AssociateTag = "newmobiles0d-20"; // send the ItemSearch request try { ItemSearchResponse response = amazonClient.ItemSearch(itemSearch); foreach (var item in response.Items[0].Item) { if (!hasReviews) { // Getting title Console.WriteLine("Title: " + item.ItemAttributes.Title); //Getting manufacturer of the item Console.WriteLine("Manufacturer: " + item.ItemAttributes.Manufacturer); //Getting model Console.WriteLine("Model:" + item.ItemAttributes.Model); if ((item.CustomerReviews.HasReviews) == true) { string str = item.CustomerReviews.IFrameURL; string final_response = ""; try { //Getting html from IFrame URL HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(str); req.Method = "POST"; HttpWebResponse res = (HttpWebResponse)req.GetResponse(); StreamReader stream = new StreamReader(res.GetResponseStream()); final_response = stream.ReadToEnd(); GetMainPageHtml(final_response, prod.Id); } catch (Exception e) { Console.WriteLine(e); } } } else { break; } } } catch (Exception e1) { } } Console.WriteLine("done...enter any key to continue>"); Console.ReadLine(); }
private void SearchNow(int page) { listBoxResult.Items.Clear(); amazonProgressControl.labelStatus.Text = StringTable.SearchWebService; amazonProgressControl.progressBar.Value = 0; amazonProgressControl.Visible = true; amazonProgressControl.Refresh(); ItemSearchRequest request = new ItemSearchRequest(); request.Artist = textBoxArtist.Text; request.Title = textBoxTitle.Text; request.Keywords = textBoxEAN.Text; request.ItemPage = (page + 1).ToString(); request.ResponseGroup = new string[] { "Large", "Tracks" }; request.SearchIndex = "Music"; AmazonSort sort = ((AmazonSortItem)comboBoxSort.Items[comboBoxSort.SelectedIndex]).sort; switch (sort) { case AmazonSort.YearDescend: request.Sort = "-releasedate"; break; case AmazonSort.YearAscend: request.Sort = "releasedate"; break; case AmazonSort.TitleAscend: request.Sort = "titlerank"; break; case AmazonSort.TitleDescend: request.Sort = "-titlerank"; break; case AmazonSort.BestSelling: request.Sort = "salesrank"; break; } AWSECommerceServicePortTypeClient amazonClient = new AWSECommerceServicePortTypeClient(); ItemSearch itemSearch = new ItemSearch(); itemSearch.Request = new ItemSearchRequest[] { request }; itemSearch.AWSAccessKeyId = "0FN016GTSMZHJD0C7YG2"; itemSearch.AssociateTag = "hitbase-21"; bool nothingFound = false; ItemSearchResponse searchResult = null; try { searchResult = amazonClient.ItemSearch(itemSearch); } catch { nothingFound = true; } if (!nothingFound) { int totalCount = Convert.ToInt32(searchResult.Items[0].TotalResults); labelResult.Text = String.Format(StringTable.Result, totalCount); if (totalCount < 1) // Leider nichts gefunden { amazonProgressControl.Visible = false; return; } WebClient webclient = new WebClient(); webclient.UseDefaultCredentials = true; webclient.Proxy.Credentials = CredentialCache.DefaultCredentials; amazonProgressControl.progressBar.Maximum = searchResult.Items[0].Item.Length; int count = 0; foreach (Items searchItems in searchResult.Items) { foreach (Item details in searchItems.Item) { amazonProgressControl.labelStatus.Text = String.Format(StringTable.ReadingResult, count + 1, searchItems.Item.Length); amazonProgressControl.labelStatus.Refresh(); CDListBoxWithCoverItem item = new CDListBoxWithCoverItem(); if (details.ItemAttributes.Artist != null && details.ItemAttributes.Artist.Length > 0) { item.Artist = details.ItemAttributes.Artist[0].ToString(); } item.Title = details.ItemAttributes.Title; item.Label = details.ItemAttributes.Label; if (details.ItemAttributes.ReleaseDate != null) { item.Year = details.ItemAttributes.ReleaseDate; } else { if (details.ItemAttributes.PublicationDate != null) { item.Year = details.ItemAttributes.PublicationDate; } } item.ASIN = details.ASIN; item.EAN = details.ItemAttributes.EAN; /*if (details.CustomerReviews != null) * item.Ranking = details.CustomerReviews.AverageRating; * else * item.Ranking = 0;*/ if (details.EditorialReviews != null && details.EditorialReviews.Length > 0) { item.EditorNotes = details.EditorialReviews[0].Content; } if (details.Tracks != null) { item.CD = new CDItem[details.Tracks.Length]; foreach (TracksDisc disc in details.Tracks) { int discNumber = Convert.ToInt32(disc.Number) - 1; item.CD[discNumber] = new CDItem(); item.CD[discNumber].Tracks = new string[disc.Track.Length]; foreach (TracksDiscTrack track in disc.Track) { int trackNumber = Convert.ToInt32(track.Number) - 1; // Das hier wird wohl (von WCF?) fälschlicherweise als CodePage 1252 interpretiert, obwohl es UTF-8 ist. // Muss dann konvertiert werden. Encoding iso = Encoding.GetEncoding("Windows-1252"); Encoding utf8 = Encoding.UTF8; byte[] utfBytes = iso.GetBytes(track.Value); string msg = utf8.GetString(utfBytes); item.CD[discNumber].Tracks[trackNumber] = msg; } } } else { // Wenn keine Track-Daten vorhanden sind, ein Pseudo-Track erzeugen item.CD = new CDItem[1]; item.CD[0] = new CDItem(); item.CD[0].Tracks = new string[1]; item.CD[0].Tracks[0] = StringTable.Unknown; } if (details.SmallImage != null) { item.smallImageUrl = details.SmallImage.URL; } if (details.MediumImage != null) { item.mediumImageUrl = details.MediumImage.URL; } if (details.LargeImage != null) { item.largeImageUrl = details.LargeImage.URL; } if (details.ImageSets != null && details.ImageSets.Length > 0) { //foreach (ImageSet[] imgSet in details.ImageSets) { foreach (ImageSet imageSet in details.ImageSets) { if (imageSet.Category == "variant") { if (imageSet.SmallImage != null) { item.backCoverSmallImageUrl = imageSet.SmallImage.URL; } if (imageSet.MediumImage != null) { item.backCoverMediumImageUrl = imageSet.MediumImage.URL; } if (imageSet.LargeImage != null) { item.backCoverLargeImageUrl = imageSet.LargeImage.URL; } } } } } item.Image = GetImage(webclient, details); listBoxResult.Items.Add(item); amazonProgressControl.progressBar.PerformStep(); count++; } } if (totalCount > 10) { pagerControl.NumberOfPages = (totalCount + 9) / 10; pagerControl.Visible = true; } else { pagerControl.Visible = false; } } else { labelResult.Text = String.Format(StringTable.Result, 0); pagerControl.Visible = false; } amazonProgressControl.Visible = false; }
public bool SearchForMovie(string movieName, int maxResults) { _locale = AmazonLocale.FromString(Properties.Settings.Default.AmazonLocale); BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); binding.MaxReceivedMessageSize = int.MaxValue; client = new AWSECommerceServicePortTypeClient( binding, new EndpointAddress(_locale.URL) ); client.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior()); try { ItemSearchRequest req = new ItemSearchRequest(); req.SearchIndex = Properties.Settings.Default.AmazonSearchMode; req.Title = movieName; req.ItemPage = @"1"; req.ResponseGroup = new string[] { "Medium", "Subjects" }; ItemSearch iSearch = new ItemSearch(); iSearch.Request = new ItemSearchRequest[] { req }; iSearch.AWSAccessKeyId = Properties.Settings.Default.AWEAccessKeyId; ItemSearchResponse res = client.ItemSearch(iSearch); if (res.Items[0].Item.Length > 0) { Item[] amazonItems = res.Items[0].Item; int itemsToProcess = Math.Min(amazonItems.Length, maxResults); if (amazonItems != null) { // convert Amazon Items to generic collection of DVDs OMLSDKTitle[] searchResults = new OMLSDKTitle[itemsToProcess]; for (int i = 0; i < itemsToProcess; i++) { searchResults[i] = AmazonToOML.TitleFromAmazonItem(amazonItems[i]); } int totalPages = 0; int totalItems = 0; if (res.Items[0].TotalPages != null) totalPages = Convert.ToInt32(res.Items[0].TotalPages); if (res.Items[0].TotalResults != null) totalItems = Convert.ToInt32(res.Items[0].TotalResults); _searchResult = (new AmazonSearchResult(searchResults, totalPages, totalItems)); } else { _searchResult = (new AmazonSearchResult(null, 0, 0)); } return true; } } catch { _searchResult = (new AmazonSearchResult(null, 0, 0)); } return false; }