예제 #1
0
        private List <AsinProductData> GetDataFromMws(List <string> requestedAsins)
        {
            List <AsinProductData> asinData = new List <AsinProductData>();

            string accessKey     = System.Configuration.ConfigurationManager.AppSettings["MwsAccK"];
            string secretKey     = System.Configuration.ConfigurationManager.AppSettings["MwsSecK"];
            string sellerId      = System.Configuration.ConfigurationManager.AppSettings["MwsSeller"];
            string marketplaceId = System.Configuration.ConfigurationManager.AppSettings["MwsMktpl"];

            MarketplaceWebServiceProductsConfig config = new MarketplaceWebServiceProductsConfig();

            config.ServiceURL = "https://mws.amazonservices.com ";
            config.SetUserAgentHeader("CMA", "1.0", "C#", new string[] { });
            MarketplaceWebServiceProductsClient client = new MarketplaceWebServiceProductsClient(accessKey, secretKey, config);

            MarketplaceWebServiceProducts.Model.GetCompetitivePricingForASINRequest request = new MarketplaceWebServiceProducts.Model.GetCompetitivePricingForASINRequest();
            request.ASINList      = new MarketplaceWebServiceProducts.Model.ASINListType();
            request.ASINList.ASIN = requestedAsins;
            request.SellerId      = System.Configuration.ConfigurationManager.AppSettings["MwsSeller"];
            request.MarketplaceId = System.Configuration.ConfigurationManager.AppSettings["MwsMktpl"];


            MarketplaceWebServiceProducts.Model.GetCompetitivePricingForASINResponse response = new MarketplaceWebServiceProducts.Model.GetCompetitivePricingForASINResponse();


            try { response = client.GetCompetitivePricingForASIN(request); } catch {}
            while (response.ResponseHeaderMetadata == null || response.ResponseHeaderMetadata.QuotaRemaining < 1000)
            {
                if (response.ResponseHeaderMetadata == null)
                {
                    this.StatusDescription = string.Format("No response given to MWS Request");
                }
                else
                {
                    this.StatusDescription = string.Format("API Quota reached. Remaining: {0} of {1}, Resets: {2},", response.ResponseHeaderMetadata.QuotaRemaining, response.ResponseHeaderMetadata.QuotaMax, response.ResponseHeaderMetadata.QuotaResetsAt.Value.ToShortTimeString());
                }

                Thread.Sleep(20000);
                try { response = client.GetCompetitivePricingForASIN(request); } catch {}
            }

            foreach (var result in response.GetCompetitivePricingForASINResult)
            {
                AsinProductData asinDataItem = new AsinProductData();
                asinDataItem.Asin = result.ASIN;
                if (result.IsSetProduct())
                {
                    if (result.Product.IsSetSalesRankings())
                    {
                        foreach (var salesRank in result.Product.SalesRankings.SalesRank)
                        {
                            if (salesRank.ProductCategoryId.Contains("display"))
                            {
                                asinDataItem.SalesRankTopLevel         = (int)salesRank.Rank;
                                asinDataItem.SalesRankTopLevelCategory = salesRank.ProductCategoryId;
                            }
                            else if (!asinDataItem.SalesRankSecondary.ContainsKey(salesRank.ProductCategoryId))
                            {
                                asinDataItem.SalesRankSecondary.Add(salesRank.ProductCategoryId, (int)salesRank.Rank);
                            }
                        }
                    }
                    if (result.Product.IsSetCompetitivePricing())
                    {
                        foreach (var price in result.Product.CompetitivePricing.CompetitivePrices.CompetitivePrice)
                        {
                            if (price.CompetitivePriceId.Equals("1"))
                            {
                                asinDataItem.CurrentlyOwnBuyBox = price.belongsToRequester;
                                if (price.IsSetPrice() && price.Price.IsSetLandedPrice())
                                {
                                    asinDataItem.BuyBoxTotalPrice = price.Price.LandedPrice.Amount;
                                }
                            }
                        }
                    }
                }

                asinData.Add(asinDataItem);
            }

            return(asinData);
        }
    private List<AsinProductData> GetDataFromMws(List<string> requestedAsins)
    {
      List<AsinProductData> asinData = new List<AsinProductData>();

      string accessKey = System.Configuration.ConfigurationManager.AppSettings["MwsAccK"];
      string secretKey = System.Configuration.ConfigurationManager.AppSettings["MwsSecK"];
      string sellerId = System.Configuration.ConfigurationManager.AppSettings["MwsSeller"];
      string marketplaceId = System.Configuration.ConfigurationManager.AppSettings["MwsMktpl"];

      MarketplaceWebServiceProductsConfig config = new MarketplaceWebServiceProductsConfig();
      config.ServiceURL = "https://mws.amazonservices.com ";
      config.SetUserAgentHeader("CMA", "1.0", "C#", new string[] { });
      MarketplaceWebServiceProductsClient client = new MarketplaceWebServiceProductsClient(accessKey, secretKey, config);

      MarketplaceWebServiceProducts.Model.GetCompetitivePricingForASINRequest request = new MarketplaceWebServiceProducts.Model.GetCompetitivePricingForASINRequest();
      request.ASINList = new MarketplaceWebServiceProducts.Model.ASINListType();
      request.ASINList.ASIN = requestedAsins;
      request.SellerId = System.Configuration.ConfigurationManager.AppSettings["MwsSeller"];
      request.MarketplaceId = System.Configuration.ConfigurationManager.AppSettings["MwsMktpl"];


      MarketplaceWebServiceProducts.Model.GetCompetitivePricingForASINResponse response = new MarketplaceWebServiceProducts.Model.GetCompetitivePricingForASINResponse();


      try { response = client.GetCompetitivePricingForASIN(request); } catch {}
      while (response.ResponseHeaderMetadata == null || response.ResponseHeaderMetadata.QuotaRemaining < 1000)
      {
        if (response.ResponseHeaderMetadata == null)
        {
          this.StatusDescription = string.Format("No response given to MWS Request");
        }
        else
          this.StatusDescription = string.Format("API Quota reached. Remaining: {0} of {1}, Resets: {2},", response.ResponseHeaderMetadata.QuotaRemaining, response.ResponseHeaderMetadata.QuotaMax, response.ResponseHeaderMetadata.QuotaResetsAt.Value.ToShortTimeString());

        Thread.Sleep(20000);
        try { response = client.GetCompetitivePricingForASIN(request); } catch {}
      }

      foreach (var result in response.GetCompetitivePricingForASINResult)
      {
        AsinProductData asinDataItem = new AsinProductData();
        asinDataItem.Asin = result.ASIN;
        if (result.IsSetProduct())
        {
          if (result.Product.IsSetSalesRankings())
          {
            foreach (var salesRank in result.Product.SalesRankings.SalesRank)
            {
              if (salesRank.ProductCategoryId.Contains("display"))
              {
                asinDataItem.SalesRankTopLevel = (int)salesRank.Rank;
                asinDataItem.SalesRankTopLevelCategory = salesRank.ProductCategoryId;
              }
              else if (!asinDataItem.SalesRankSecondary.ContainsKey(salesRank.ProductCategoryId))
              {
                asinDataItem.SalesRankSecondary.Add(salesRank.ProductCategoryId, (int)salesRank.Rank);
              }
            }
          }
          if (result.Product.IsSetCompetitivePricing())
          {
            foreach (var price in result.Product.CompetitivePricing.CompetitivePrices.CompetitivePrice)
            {
              if (price.CompetitivePriceId.Equals("1"))
              {
                asinDataItem.CurrentlyOwnBuyBox = price.belongsToRequester;
                if (price.IsSetPrice() && price.Price.IsSetLandedPrice())
                  asinDataItem.BuyBoxTotalPrice = price.Price.LandedPrice.Amount;
              }
            }
          }
        }
        
        asinData.Add(asinDataItem);
      }

      return asinData;
    }