public AmazonMwsDataAccessor() { var config = new MarketplaceWebServiceProductsConfig(); config.ServiceURL = SERVICEURL; config.SignatureMethod = "HmacSHA256"; _productClient = new MarketplaceWebServiceProductsClient("AmazonJavascriptScratchpad", "1.0", ACCESSKEY, SECRETKEY, config); }
public MarketplaceWebServiceProducts(string appName, string appVersion, string accessKey, string secretKey, string serviceURL, string sellerId, string mwsAuthToken, string marketplaceId) { //Create a configuration object MarketplaceWebServiceProductsConfig config = new MarketplaceWebServiceProductsConfig(); config.ServiceURL = serviceURL; // Create the client itself productClient = new MarketplaceWebServiceProductsClient(appName, appVersion, accessKey, secretKey, config); }
private void InitMwsProductClient() { var mwsConfig = new MarketplaceWebServiceProductsConfig(); mwsConfig.SetUserAgentHeader( "Speadbot", "1.0", "C#" ); mwsConfig.ServiceURL = AmazonSettings.ServiceUrl; _mswProductsClient = new MarketplaceWebServiceProductsClient( AmazonSettings.AwsAccessKeyId, AmazonSettings.AwsSecretAccessKey, mwsConfig ); }
/// <summary> /// Get Competitive Pricing For ASIN /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnCompetitivePricingSearch_Click(object sender, RoutedEventArgs e) { string SellerId = CommonValue.strMerchantId; string MarketplaceId = CommonValue.strMarketplaceId; string AccessKeyId = CommonValue.strAccessKeyId; string SecretKeyId = CommonValue.strSecretKeyId; string ApplicationVersion = CommonValue.strApplicationVersion; string ApplicationName = CommonValue.strApplicationName; string MWSAuthToken = CommonValue.strMWSAuthToken; string strbuff = string.Empty; MarketplaceWebServiceProductsConfig config = new MarketplaceWebServiceProductsConfig(); config.ServiceURL = CommonValue.strServiceURL; MarketplaceWebServiceProductsClient client = new MarketplaceWebServiceProductsClient( ApplicationName, ApplicationVersion, AccessKeyId, SecretKeyId, config); GetCompetitivePricingForASINRequest request = new GetCompetitivePricingForASINRequest(); request.SellerId = SellerId; request.MarketplaceId = MarketplaceId; ASINListType asinListType = new ASINListType(); asinListType.ASIN.Add(txtSearchValue.Text); request.ASINList = asinListType; request.MWSAuthToken = MWSAuthToken; GetCompetitivePricingForASINResponse response = client.GetCompetitivePricingForASIN(request); if (response.IsSetGetCompetitivePricingForASINResult()) { foreach (GetCompetitivePricingForASINResult getCompetitivePricingForASINResult in response.GetCompetitivePricingForASINResult) { if (getCompetitivePricingForASINResult.IsSetProduct()) { Product product = getCompetitivePricingForASINResult.Product; if (product.IsSetCompetitivePricing()) { CompetitivePricingType competitivePricing = product.CompetitivePricing; if (competitivePricing.IsSetCompetitivePrices()) { CompetitivePriceList competitivePrices = competitivePricing.CompetitivePrices; foreach (CompetitivePriceType priceList in competitivePrices.CompetitivePrice) { strbuff += "価格:" + priceList.Price.LandedPrice.Amount + System.Environment.NewLine; } } } } } txtCompetitivePricingResult.Text = strbuff; } }
public GetMatchingProduct(string accessKeyId, string secretAccessKey, string merchantId, string marketplaceId, string applicationName, string applicationVersion) { config = new MarketplaceWebServiceProductsConfig(); config.ServiceURL = "https://mws.amazonservices.com/Products/2011-10-01"; GetMatchingProduct.merchantId = merchantId; GetMatchingProduct.marketplaceId = marketplaceId; service = new MarketplaceWebServiceProductsClient( applicationName, applicationVersion, accessKeyId, secretAccessKey, config); }
public MarketplaceWebServiceProductsClient GetMWSProductsClient() { MarketplaceWebServiceProductsConfig config = new MarketplaceWebServiceProductsConfig(); config.ServiceURL = "https://mws.amazonservices.com/Products/2011-10-01"; MarketplaceWebServiceProductsClient service = new MarketplaceWebServiceProductsClient( "berkeley", "1.0", this.AccessKeyId, this.SecretAccessKey, config); return(service); }
public MwsProductsApi(string sellerId, string marketPlaceId, string accessKeyId, string secretAccessKeyId, string serviceUrl) { m_sellerId = sellerId; m_marketPlaceId = marketPlaceId; MarketplaceWebServiceProductsConfig config = new MarketplaceWebServiceProductsConfig { ServiceURL = serviceUrl }; m_productClient = new MarketplaceWebServiceProductsClient(string.Empty, string.Empty, accessKeyId, secretAccessKeyId, config); MarketplaceWebServiceConfig configService = new MarketplaceWebServiceConfig() .WithServiceURL("https://mws.amazonservices.com"); configService.SetUserAgentHeader(string.Empty, string.Empty, "C#"); m_service = new MarketplaceWebServiceClient(accessKeyId, secretAccessKeyId, configService); }
public object GetBySKU(string sku) { var client = new MarketplaceWebServiceProductsClient(_accessKey, _secretKey); var resp = client.GetMatchingProduct(new GetMatchingProductRequest( _merchantId, _marketPlaceId, new ASINListType { ASIN = new List <string> { sku } })); var product = resp.GetMatchingProductResult.FirstOrDefault(); if (product?.Error != null) { throw new Exception(product.Error.Detail.Any.FirstOrDefault()?.ToString()); } return(product?.Product); }
static void Main(string[] args) { /* Config */ var sellerId = "<seller id>"; var accessKey = "<access key"; var marketPlaceId = "<marketplace id>"; var secretKey = "<secret key>"; var appName = "<application name>"; var appVersion = "<application version>"; /* Example Products API Client */ var config = new MarketplaceWebServiceProductsConfig { ServiceURL = "https://mws.amazonservices.com" }; var client = new MarketplaceWebServiceProductsClient(appName, appVersion, accessKey, secretKey, config); var request = new GetMatchingProductForIdRequest(); request.IdList = new IdListType(); request.IdType = "<id type>"; // UPC, ISBN, EAN, ASIN request.IdList.Id.Add("<id>"); request.MarketplaceId = marketPlaceId; try { // try to get the response from the server var response = client.GetMatchingProductForId(request); } catch (MarketplaceWebServiceProductsException ex) { // something went wrong // check the value of ErrorCode } }
public MarketplaceWebServiceProductsSample(MarketplaceWebServiceProductsClient client) { this.client = client; }
public static void xMain(string[] args) { // TODO: Set the below configuration variables before attempting to run // Developer AWS access key string accessKey = "replaceWithAccessKey"; // Developer AWS secret key string secretKey = "replaceWithSecretKey"; // The client application name string appName = "CSharpSampleCode"; // The client application version string appVersion = "1.0"; // The endpoint for region service and version (see developer guide) // ex: https://mws.amazonservices.com string serviceURL = "replaceWithServiceURL"; // Create a configuration object MarketplaceWebServiceProductsConfig config = new MarketplaceWebServiceProductsConfig(); config.ServiceURL = serviceURL; // Set other client connection configurations here if needed // Create the client itself MarketplaceWebServiceProducts client = new MarketplaceWebServiceProductsClient(appName, appVersion, accessKey, secretKey, config); MarketplaceWebServiceProductsSample sample = new MarketplaceWebServiceProductsSample(client); // Uncomment the operation you'd like to test here // TODO: Modify the request created in the Invoke method to be valid try { IMWSResponse response = null; // response = sample.InvokeGetCompetitivePricingForASIN(); // response = sample.InvokeGetCompetitivePricingForSKU(); // response = sample.InvokeGetLowestOfferListingsForASIN(); // response = sample.InvokeGetLowestOfferListingsForSKU(); // response = sample.InvokeGetLowestPricedOffersForASIN(); // response = sample.InvokeGetLowestPricedOffersForSKU(); // response = sample.InvokeGetMatchingProduct(); // response = sample.InvokeGetMatchingProductForId(); // response = sample.InvokeGetMyPriceForASIN(); // response = sample.InvokeGetMyPriceForSKU(); // response = sample.InvokeGetProductCategoriesForASIN(); // response = sample.InvokeGetProductCategoriesForSKU(); // response = sample.InvokeGetServiceStatus(); // response = sample.InvokeListMatchingProducts(); Console.WriteLine("Response:"); ResponseHeaderMetadata rhmd = response.ResponseHeaderMetadata; // We recommend logging the request id and timestamp of every call. Console.WriteLine("RequestId: " + rhmd.RequestId); Console.WriteLine("Timestamp: " + rhmd.Timestamp); string responseXml = response.ToXML(); Console.WriteLine(responseXml); } catch (MarketplaceWebServiceProductsException ex) { // Exception properties are important for diagnostics. ResponseHeaderMetadata rhmd = ex.ResponseHeaderMetadata; Console.WriteLine("Service Exception:"); if(rhmd != null) { Console.WriteLine("RequestId: " + rhmd.RequestId); Console.WriteLine("Timestamp: " + rhmd.Timestamp); } Console.WriteLine("Message: " + ex.Message); Console.WriteLine("StatusCode: " + ex.StatusCode); Console.WriteLine("ErrorCode: " + ex.ErrorCode); Console.WriteLine("ErrorType: " + ex.ErrorType); throw ex; } }
/** * Samples for Marketplace Web Service Products functionality */ public static void Main(string [] args) { Console.WriteLine("==========================================="); Console.WriteLine("Welcome to Marketplace Web Service Products Samples!"); Console.WriteLine("==========================================="); Console.WriteLine("To get started:"); Console.WriteLine("==========================================="); Console.WriteLine(" - Fill in your MWS credentials"); Console.WriteLine(" - Uncomment sample you're interested in trying"); Console.WriteLine(" - Set request with desired parameters"); Console.WriteLine(" - Hit F5 to run!"); Console.WriteLine(); Console.WriteLine("==========================================="); Console.WriteLine("Samples Output"); Console.WriteLine("==========================================="); Console.WriteLine(); /************************************************************************ * Access Key ID and Secret Access Key ID ***********************************************************************/ String accessKeyId = "<Your Access Key Id>"; String secretAccessKey = "<Your Secret Access Key>"; String merchantId = "<Your Merchant Id>"; String marketplaceId = "<Your Marketplace Id>"; /************************************************************************ * The application name and version are included in each MWS call's * HTTP User-Agent field. ***********************************************************************/ const string applicationName = "<Your Application Name>"; const string applicationVersion = "<Your Application Version>"; /************************************************************************ * Uncomment to try advanced configuration options. Available options are: * * - Signature Version * - Proxy Host and Proxy Port * - Service URL * - User Agent String to be sent to Marketplace Web Service Products service * ***********************************************************************/ MarketplaceWebServiceProductsConfig config = new MarketplaceWebServiceProductsConfig(); // // IMPORTANT: Uncomment out the appropriate line for the country you wish // to sell in: // // United States: // config.ServiceURL = "https://mws.amazonservices.com/Products/2011-10-01"; // // Canada: // config.ServiceURL = "https://mws.amazonservices.ca/Products/2011-10-01"; // // Europe: // config.ServiceURL = "https://mws-eu.amazonservices.com/Products/2011-10-01"; // // Japan: // config.ServiceURL = "https://mws.amazonservices.jp/Products/2011-10-01"; // // China: // config.ServiceURL = "https://mws.amazonservices.com.cn/Products/2011-10-01"; // /************************************************************************ * Instantiate Implementation of Marketplace Web Service Products ***********************************************************************/ MarketplaceWebServiceProductsClient service = new MarketplaceWebServiceProductsClient( applicationName, applicationVersion, accessKeyId, secretAccessKey, config); /************************************************************************ * Uncomment to try out Mock Service that simulates Marketplace Web Service Products * responses without calling Marketplace Web Service Products service. * * Responses are loaded from local XML files. You can tweak XML files to * experiment with various outputs during development * * XML files available under MarketplaceWebServiceProducts\Mock tree * ***********************************************************************/ // MarketplaceWebServiceProducts service = new MarketplaceWebServiceProductsMock(); /************************************************************************ * Uncomment to invoke Get Matching Product Action ***********************************************************************/ // GetMatchingProductRequest request = new GetMatchingProductRequest(); // @TODO: set request parameters here // request.SellerId = merchantId; // GetMatchingProductSample.InvokeGetMatchingProduct(service, request); /************************************************************************ * Uncomment to invoke Get Lowest Offer Listings For ASIN Action ***********************************************************************/ // GetLowestOfferListingsForASINRequest request = new GetLowestOfferListingsForASINRequest(); // @TODO: set request parameters here // request.SellerId = merchantId; // GetLowestOfferListingsForASINSample.InvokeGetLowestOfferListingsForASIN(service, request); /************************************************************************ * Uncomment to invoke Get Service Status Action ***********************************************************************/ // GetServiceStatusRequest request = new GetServiceStatusRequest(); // @TODO: set request parameters here // request.SellerId = merchantId; // GetServiceStatusSample.InvokeGetServiceStatus(service, request); /************************************************************************ * Uncomment to invoke Get Matching Product For Id Action ***********************************************************************/ // GetMatchingProductForIdRequest request = new GetMatchingProductForIdRequest(); // @TODO: set request parameters here // request.SellerId = merchantId; // GetMatchingProductForIdSample.InvokeGetMatchingProductForId(service, request); /************************************************************************ * Uncomment to invoke Get My Price For SKU Action ***********************************************************************/ // GetMyPriceForSKURequest request = new GetMyPriceForSKURequest(); // @TODO: set request parameters here // request.SellerId = merchantId; // GetMyPriceForSKUSample.InvokeGetMyPriceForSKU(service, request); /************************************************************************ * Uncomment to invoke List Matching Products Action ***********************************************************************/ // ListMatchingProductsRequest request = new ListMatchingProductsRequest(); // @TODO: set request parameters here // request.SellerId = merchantId; // ListMatchingProductsSample.InvokeListMatchingProducts(service, request); /************************************************************************ * Uncomment to invoke Get Competitive Pricing For SKU Action ***********************************************************************/ // GetCompetitivePricingForSKURequest request = new GetCompetitivePricingForSKURequest(); // @TODO: set request parameters here // request.SellerId = merchantId; // GetCompetitivePricingForSKUSample.InvokeGetCompetitivePricingForSKU(service, request); /************************************************************************ * Uncomment to invoke Get Competitive Pricing For ASIN Action ***********************************************************************/ // GetCompetitivePricingForASINRequest request = new GetCompetitivePricingForASINRequest(); // @TODO: set request parameters here // request.SellerId = merchantId; // GetCompetitivePricingForASINSample.InvokeGetCompetitivePricingForASIN(service, request); /************************************************************************ * Uncomment to invoke Get Product Categories For SKU Action ***********************************************************************/ // GetProductCategoriesForSKURequest request = new GetProductCategoriesForSKURequest(); // @TODO: set request parameters here // request.SellerId = merchantId; // GetProductCategoriesForSKUSample.InvokeGetProductCategoriesForSKU(service, request); /************************************************************************ * Uncomment to invoke Get My Price For ASIN Action ***********************************************************************/ // GetMyPriceForASINRequest request = new GetMyPriceForASINRequest(); // @TODO: set request parameters here // request.SellerId = merchantId; // GetMyPriceForASINSample.InvokeGetMyPriceForASIN(service, request); /************************************************************************ * Uncomment to invoke Get Lowest Offer Listings For SKU Action ***********************************************************************/ // GetLowestOfferListingsForSKURequest request = new GetLowestOfferListingsForSKURequest(); // @TODO: set request parameters here // request.SellerId = merchantId; // GetLowestOfferListingsForSKUSample.InvokeGetLowestOfferListingsForSKU(service, request); /************************************************************************ * Uncomment to invoke Get Product Categories For ASIN Action ***********************************************************************/ // GetProductCategoriesForASINRequest request = new GetProductCategoriesForASINRequest(); // @TODO: set request parameters here // request.SellerId = merchantId; // GetProductCategoriesForASINSample.InvokeGetProductCategoriesForASIN(service, request); Console.WriteLine(); Console.WriteLine("==========================================="); Console.WriteLine("End of output. You can close this window"); Console.WriteLine("==========================================="); System.Threading.Thread.Sleep(50000); }
public List<AmazonCategoryList> GetProductCategories(List<string> requestedAsins) { List<AmazonCategoryList> asinData = new List<AmazonCategoryList>(); 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); requestedAsins = requestedAsins.Distinct().ToList(); StringBuilder csv = new StringBuilder(); csv.Append(string.Format("{0},{1},{2}{3}", "ASIN", "CatID", "CatName", Environment.NewLine)); for (int i = 0; i < requestedAsins.Count; i++) { string asin = requestedAsins[i]; Console.WriteLine("{0}/{1} ({2:0.00}%)", i, requestedAsins.Count, i * 100.0 / requestedAsins.Count); MarketplaceWebServiceProducts.Model.GetProductCategoriesForASINRequest request = new MarketplaceWebServiceProducts.Model.GetProductCategoriesForASINRequest(); request.ASIN = asin; request.SellerId = System.Configuration.ConfigurationManager.AppSettings["MwsSeller"]; request.MarketplaceId = System.Configuration.ConfigurationManager.AppSettings["MwsMktpl"]; MarketplaceWebServiceProducts.Model.GetProductCategoriesForASINResponse response = new MarketplaceWebServiceProducts.Model.GetProductCategoriesForASINResponse(); try { response = client.GetProductCategoriesForASIN(request); } catch { } while (response.ResponseHeaderMetadata == null || response.ResponseHeaderMetadata.QuotaRemaining < 10) { if (response.ResponseHeaderMetadata == null) { Console.WriteLine(string.Format("No response given to MWS Request")); break; } else Console.WriteLine(string.Format("API Quota reached. Remaining: {0} of {1}, Resets: {2},", response.ResponseHeaderMetadata.QuotaRemaining, response.ResponseHeaderMetadata.QuotaMax, response.ResponseHeaderMetadata.QuotaResetsAt.Value.ToShortTimeString())); Thread.Sleep(30000); try { response = client.GetProductCategoriesForASIN(request); } catch { } } if (response != null && response.IsSetGetProductCategoriesForASINResult()) { if (response.GetProductCategoriesForASINResult.IsSetSelf()) { AmazonCategoryList asinDeets = new AmazonCategoryList(); asinDeets.Asin = asin; foreach (var cat in response.GetProductCategoriesForASINResult.Self) { var newLine = string.Format("{0},{1},{2}{3}", asin, cat.ProductCategoryId, cat.ProductCategoryName, Environment.NewLine); csv.Append(newLine); } } } Thread.Sleep(5000); } try { File.WriteAllText("AmazonCategories.csv", csv.ToString()); } catch (Exception e) { } Console.WriteLine("CHECK THE NEXT PART IF IT FAILED."); return asinData; }
/// <summary> /// Get Lowest Offer Listings For ASIN /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnLowestOfferListingsSearch_Click(object sender, RoutedEventArgs e) { string SellerId = CommonValue.strMerchantId; string MarketplaceId = CommonValue.strMarketplaceId; string AccessKeyId = CommonValue.strAccessKeyId; string SecretKeyId = CommonValue.strSecretKeyId; string ApplicationVersion = CommonValue.strApplicationVersion; string ApplicationName = CommonValue.strApplicationName; string MWSAuthToken = CommonValue.strMWSAuthToken; string strbuff = string.Empty; MarketplaceWebServiceProductsConfig config = new MarketplaceWebServiceProductsConfig(); config.ServiceURL = CommonValue.strServiceURL; MarketplaceWebServiceProductsClient client = new MarketplaceWebServiceProductsClient( ApplicationName, ApplicationVersion, AccessKeyId, SecretKeyId, config); GetLowestOfferListingsForASINRequest request = new GetLowestOfferListingsForASINRequest(); request.SellerId = SellerId; request.MarketplaceId = MarketplaceId; ASINListType asinListType = new ASINListType(); asinListType.ASIN.Add(txtLowestOfferListingsSearchValue.Text.ToString().Trim()); request.ASINList = asinListType; GetLowestOfferListingsForASINResponse response = client.GetLowestOfferListingsForASIN(request); if (response.IsSetGetLowestOfferListingsForASINResult()) { List<GetLowestOfferListingsForASINResult> getLowestOfferListingsForASINResultList = response.GetLowestOfferListingsForASINResult; foreach (GetLowestOfferListingsForASINResult getLowestOfferListingsForASINResult in getLowestOfferListingsForASINResultList) { if (getLowestOfferListingsForASINResult.IsSetProduct()) { Product product = getLowestOfferListingsForASINResult.Product; if (product.IsSetLowestOfferListings()) { LowestOfferListingList lowestOfferListingList = product.LowestOfferListings; foreach (LowestOfferListingType lowestOfferListing in lowestOfferListingList.LowestOfferListing) { strbuff += "価格:" + lowestOfferListing.Price.ListingPrice.Amount + System.Environment.NewLine; } } } } txtLowestOfferListingsResult.Text = strbuff; } }
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); }
/// <summary> /// Get ListMatching Products /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnListMatchingSearch_Click(object sender, RoutedEventArgs e) { string SellerId = CommonValue.strMerchantId; string MarketplaceId = CommonValue.strMarketplaceId; string AccessKeyId = CommonValue.strAccessKeyId; string SecretKeyId = CommonValue.strSecretKeyId; string ApplicationVersion = CommonValue.strApplicationVersion; string ApplicationName = CommonValue.strApplicationName; string MWSAuthToken = CommonValue.strMWSAuthToken; string strbuff = string.Empty; MarketplaceWebServiceProductsConfig config = new MarketplaceWebServiceProductsConfig(); config.ServiceURL = CommonValue.strServiceURL; MarketplaceWebServiceProductsClient client = new MarketplaceWebServiceProductsClient( ApplicationName, ApplicationVersion, AccessKeyId, SecretKeyId, config); ListMatchingProductsRequest request = new ListMatchingProductsRequest(); request.SellerId = SellerId; request.MWSAuthToken = MWSAuthToken; request.MarketplaceId = MarketplaceId; request.Query = txtListMatchingSearchValue.Text.ToString().Trim(); ListMatchingProductsResponse response = client.ListMatchingProducts(request); if (response.IsSetListMatchingProductsResult()) { ListMatchingProductsResult ListMatchingProductsResult = response.ListMatchingProductsResult; if (ListMatchingProductsResult.IsSetProducts()) { ProductList productList = ListMatchingProductsResult.Products; List<Product> products = productList.Product; foreach (Product product in products) { System.Xml.XmlElement elements = (System.Xml.XmlElement)product.AttributeSets.Any[0]; foreach (System.Xml.XmlElement element in elements) { switch (element.LocalName) { case "Title": strbuff += element.InnerText + System.Environment.NewLine; break; default: break; } } } txtListMatchingResult.Text = strbuff; } } }
/// <summary> /// Get Service Status Info /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnServiceStatusSearch_Click(object sender, RoutedEventArgs e) { string SellerId = CommonValue.strMerchantId; string MarketplaceId = CommonValue.strMarketplaceId; string AccessKeyId = CommonValue.strAccessKeyId; string SecretKeyId = CommonValue.strSecretKeyId; string ApplicationVersion = CommonValue.strApplicationVersion; string ApplicationName = CommonValue.strApplicationName; string MWSAuthToken = CommonValue.strMWSAuthToken; MarketplaceWebServiceProductsConfig config = new MarketplaceWebServiceProductsConfig(); config.ServiceURL = CommonValue.strServiceURL; MarketplaceWebServiceProductsClient client = new MarketplaceWebServiceProductsClient( ApplicationName, ApplicationVersion, AccessKeyId, SecretKeyId, config); GetServiceStatusRequest request = new GetServiceStatusRequest(); request.SellerId = SellerId; request.MWSAuthToken = MWSAuthToken; GetServiceStatusResponse response = client.GetServiceStatus(request); if (response.IsSetGetServiceStatusResult()) { txtServiceStatusResult.Text = "利用状況:" + response.GetServiceStatusResult.Status; } }
// ������ public static void GetNumberOfOfferListings(string market_id, Dictionary<string, int> skuDict) { // Create a configuration object MarketplaceWebServiceProductsConfig config = new MarketplaceWebServiceProductsConfig(); config.ServiceURL = GlobalConfig.Instance.GetConfigValue(market_id, "serviceURL"); // Set other client connection configurations here if needed // Create the client itself //MarketplaceWebServiceProducts client = new MarketplaceWebServiceProductsClient(GlobalConfig.Instance.AppName, GlobalConfig.Instance.AppVersion, GlobalConfig.Instance.AccessKey, GlobalConfig.Instance.SecretKey, config); MarketplaceWebServiceProducts client = new MarketplaceWebServiceProductsClient(GlobalConfig.Instance.GetCommonConfigValue("appName"), GlobalConfig.Instance.GetCommonConfigValue("appVersion"), GlobalConfig.Instance.GetConfigValue(market_id, "accessKey"), GlobalConfig.Instance.GetConfigValue(market_id, "secretKey"), config); //MarketplaceWebServiceProductsSample sample = new MarketplaceWebServiceProductsSample(client, GlobalConfig.Instance.SellerId, "", GlobalConfig.Instance.MarketplaceId); MarketplaceWebServiceProductsSample sample = new MarketplaceWebServiceProductsSample(client, GlobalConfig.Instance.GetConfigValue(market_id, "sellerId"), "", GlobalConfig.Instance.GetConfigValue(market_id, "marketplaceId")); // Uncomment the operation you'd like to test here // TODO: Modify the request created in the Invoke method to be valid try { //*** todo: ������Ҫ��list����Ƭ��ÿ��20�� List<string> skuList = new List<string>(skuDict.Keys); IMWSResponse response = null; int count = int.Parse(GlobalConfig.Instance.GetCommonConfigValue("skuPriceCount")); int current_index; for (current_index = 0; current_index < skuList.Count; current_index += count) { int current_count = (current_index + count) > skuList.Count ? skuList.Count - current_index : count; List<string> skuRangeList = skuList.GetRange(current_index, current_count); { response = sample.InvokeGetCompetitivePricingForSKU(skuRangeList); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(response.ToXML()); XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDocument.NameTable); nsmgr.AddNamespace("mws", xmlDocument.GetElementsByTagName("GetCompetitivePricingForSKUResponse")[0].Attributes["xmlns"].Value); XmlNodeList xnList = xmlDocument.SelectNodes("//mws:GetCompetitivePricingForSKUResult", nsmgr); foreach (XmlNode xn in xnList) { //XmlNode target = xn.SelectSingleNode(".//mws:NumberOfOfferListings/mws:OfferListingCount", nsmgr); XmlNodeList xnListTarget = xn.SelectNodes(".//mws:NumberOfOfferListings/mws:OfferListingCount", nsmgr); foreach (XmlNode xnTarget in xnListTarget) { if (xnTarget.Attributes["condition"].Value == "New") { skuDict[xn.Attributes["SellerSKU"].Value] = int.Parse(xnTarget.InnerText); break; } } } } // Restore rate: 10 items every second System.Threading.Thread.Sleep(int.Parse(GlobalConfig.Instance.GetCommonConfigValue("skuPriceWaitTime"))); } } catch (MarketplaceWebServiceProductsException ex) { // Exception properties are important for diagnostics. ResponseHeaderMetadata rhmd = ex.ResponseHeaderMetadata; Console.WriteLine("Service Exception:"); if (rhmd != null) { Console.WriteLine("RequestId: " + rhmd.RequestId); Console.WriteLine("Timestamp: " + rhmd.Timestamp); } Console.WriteLine("Message: " + ex.Message); Console.WriteLine("StatusCode: " + ex.StatusCode); Console.WriteLine("ErrorCode: " + ex.ErrorCode); Console.WriteLine("ErrorType: " + ex.ErrorType); throw ex; } }
/// <summary> /// Get My Price For ASIN /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnMyPriceSearch_Click(object sender, RoutedEventArgs e) { string SellerId = CommonValue.strMerchantId; string MarketplaceId = CommonValue.strMarketplaceId; string AccessKeyId = CommonValue.strAccessKeyId; string SecretKeyId = CommonValue.strSecretKeyId; string ApplicationVersion = CommonValue.strApplicationVersion; string ApplicationName = CommonValue.strApplicationName; string MWSAuthToken = CommonValue.strMWSAuthToken; string strbuff = string.Empty; MarketplaceWebServiceProductsConfig config = new MarketplaceWebServiceProductsConfig(); config.ServiceURL = CommonValue.strServiceURL; MarketplaceWebServiceProductsClient client = new MarketplaceWebServiceProductsClient( ApplicationName, ApplicationVersion, AccessKeyId, SecretKeyId, config); GetMyPriceForASINRequest request = new GetMyPriceForASINRequest(); request.SellerId = SellerId; request.MarketplaceId = MarketplaceId; request.MWSAuthToken = MWSAuthToken; ASINListType asinListType = new ASINListType(); asinListType.ASIN.Add(txtMyPriceSearchValue.Text.ToString().Trim()); request.ASINList = asinListType; GetMyPriceForASINResponse response = client.GetMyPriceForASIN(request); if (response.IsSetGetMyPriceForASINResult()) { List<GetMyPriceForASINResult> getMyPriceForASINResult = response.GetMyPriceForASINResult; foreach (GetMyPriceForASINResult myPriceForASIN in getMyPriceForASINResult) { Product product = myPriceForASIN.Product; strbuff += "コンディション:" + product.Offers.Offer[0].ItemCondition + System.Environment.NewLine; strbuff += "セラーID:" + product.Offers.Offer[0].SellerId + System.Environment.NewLine; strbuff += "SKU:" + product.Offers.Offer[0].SellerSKU + System.Environment.NewLine; txtMyPriceResult.Text = strbuff; } } }
public MarketplaceWebServiceProducts(MarketplaceWebServiceProductsClient client, string sellerId, string mwsAuthToken, string marketplaceId) { productClient = client; }
/// <summary> /// Get Matching Product /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnMatchingSearch_Click(object sender, RoutedEventArgs e) { string SellerId = CommonValue.strMerchantId; string MarketplaceId = CommonValue.strMarketplaceId; string AccessKeyId = CommonValue.strAccessKeyId; string SecretKeyId = CommonValue.strSecretKeyId; string ApplicationVersion = CommonValue.strApplicationVersion; string ApplicationName = CommonValue.strApplicationName; string MWSAuthToken = CommonValue.strMWSAuthToken; string strbuff = string.Empty; MarketplaceWebServiceProductsConfig config = new MarketplaceWebServiceProductsConfig(); config.ServiceURL = CommonValue.strServiceURL; MarketplaceWebServiceProductsClient client = new MarketplaceWebServiceProductsClient( ApplicationName, ApplicationVersion, AccessKeyId, SecretKeyId, config); GetMatchingProductRequest request = new GetMatchingProductRequest(); request.SellerId = SellerId; request.MarketplaceId = MarketplaceId; ASINListType asinListType = new ASINListType(); asinListType.ASIN.Add(txtSearchValue.Text); request.ASINList = asinListType; request.MWSAuthToken = MWSAuthToken; GetMatchingProductResponse response = client.GetMatchingProduct(request); if (response.IsSetGetMatchingProductResult()) { List<GetMatchingProductResult> getMatchingProductResultList = response.GetMatchingProductResult; foreach (GetMatchingProductResult getMatchingProductResult in getMatchingProductResultList) { Product product = getMatchingProductResult.Product; System.Xml.XmlElement elements = (System.Xml.XmlElement)product.AttributeSets.Any[0]; foreach (System.Xml.XmlElement element in elements) { switch (element.LocalName) { case "Title": strbuff += "タイトル:" + element.InnerText + System.Environment.NewLine; break; case "Creator": strbuff += "著者:" + element.InnerText + System.Environment.NewLine; break; case "ListPrice": strbuff += "価格:" + element.InnerText + System.Environment.NewLine; break; case "Manufacturer": strbuff += "販売会社:" + element.InnerText + System.Environment.NewLine; break; default: break; } } txtMatchingResult.Text = strbuff; } } }
public void RunTest() { // TODO: Set the below configuration variables before attempting to run // Developer AWS access key string accessKey = "AKIAJZY7ZVPLTWQYHWYA"; // Developer AWS secret key string secretKey = "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"; // The client application name string appName = "CSharpSampleCode"; // The client application version string appVersion = "1.0"; // The endpoint for region service and version (see developer guide) // ex: https://mws.amazonservices.com string serviceURL = "https://mws.amazonservices.com"; // Create a configuration object MarketplaceWebServiceProductsConfig config = new MarketplaceWebServiceProductsConfig(); config.ServiceURL = serviceURL; // Set other client connection configurations here if needed // Create the client itself MarketplaceWebServiceProductsClient client = new MarketplaceWebServiceProductsClient(appName, appVersion, accessKey, secretKey, config); this.client = client; // Uncomment the operation you'd like to test here // TODO: Modify the request created in the Invoke method to be valid try { IMWSResponse response = null; // response = sample.InvokeGetCompetitivePricingForASIN(); // response = sample.InvokeGetCompetitivePricingForSKU(); // response = sample.InvokeGetLowestOfferListingsForASIN(); // response = sample.InvokeGetLowestOfferListingsForSKU(); // response = sample.InvokeGetLowestPricedOffersForASIN(); // response = sample.InvokeGetLowestPricedOffersForSKU(); // response = sample.InvokeGetMatchingProduct(); // response = sample.InvokeGetMatchingProductForId(); // response = sample.InvokeGetMyFeesEstimate(); response = InvokeGetMyPriceForASIN(); // response = sample.InvokeGetMyPriceForSKU(); // response = sample.InvokeGetProductCategoriesForASIN(); // response = sample.InvokeGetProductCategoriesForSKU(); // response = sample.InvokeGetServiceStatus(); // response = sample.InvokeListMatchingProducts(); Console.WriteLine("Response:"); ResponseHeaderMetadata rhmd = response.ResponseHeaderMetadata; // We recommend logging the request id and timestamp of every call. Console.WriteLine("RequestId: " + rhmd.RequestId); Console.WriteLine("Timestamp: " + rhmd.Timestamp); string responseXml = response.ToXML(); Console.WriteLine(responseXml); } catch (MarketplaceWebServiceProductsException ex) { // Exception properties are important for diagnostics. ResponseHeaderMetadata rhmd = ex.ResponseHeaderMetadata; Console.WriteLine("Service Exception:"); if (rhmd != null) { Console.WriteLine("RequestId: " + rhmd.RequestId); Console.WriteLine("Timestamp: " + rhmd.Timestamp); } Console.WriteLine("Message: " + ex.Message); Console.WriteLine("StatusCode: " + ex.StatusCode); Console.WriteLine("ErrorCode: " + ex.ErrorCode); Console.WriteLine("ErrorType: " + ex.ErrorType); throw ex; } }
public List <AmazonCategoryList> GetProductCategories(List <string> requestedAsins) { List <AmazonCategoryList> asinData = new List <AmazonCategoryList>(); 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); requestedAsins = requestedAsins.Distinct().ToList(); StringBuilder csv = new StringBuilder(); csv.Append(string.Format("{0},{1},{2}{3}", "ASIN", "CatID", "CatName", Environment.NewLine)); for (int i = 0; i < requestedAsins.Count; i++) { string asin = requestedAsins[i]; Console.WriteLine("{0}/{1} ({2:0.00}%)", i, requestedAsins.Count, i * 100.0 / requestedAsins.Count); MarketplaceWebServiceProducts.Model.GetProductCategoriesForASINRequest request = new MarketplaceWebServiceProducts.Model.GetProductCategoriesForASINRequest(); request.ASIN = asin; request.SellerId = System.Configuration.ConfigurationManager.AppSettings["MwsSeller"]; request.MarketplaceId = System.Configuration.ConfigurationManager.AppSettings["MwsMktpl"]; MarketplaceWebServiceProducts.Model.GetProductCategoriesForASINResponse response = new MarketplaceWebServiceProducts.Model.GetProductCategoriesForASINResponse(); try { response = client.GetProductCategoriesForASIN(request); } catch { } while (response.ResponseHeaderMetadata == null || response.ResponseHeaderMetadata.QuotaRemaining < 10) { if (response.ResponseHeaderMetadata == null) { Console.WriteLine(string.Format("No response given to MWS Request")); break; } else { Console.WriteLine(string.Format("API Quota reached. Remaining: {0} of {1}, Resets: {2},", response.ResponseHeaderMetadata.QuotaRemaining, response.ResponseHeaderMetadata.QuotaMax, response.ResponseHeaderMetadata.QuotaResetsAt.Value.ToShortTimeString())); } Thread.Sleep(30000); try { response = client.GetProductCategoriesForASIN(request); } catch { } } if (response != null && response.IsSetGetProductCategoriesForASINResult()) { if (response.GetProductCategoriesForASINResult.IsSetSelf()) { AmazonCategoryList asinDeets = new AmazonCategoryList(); asinDeets.Asin = asin; foreach (var cat in response.GetProductCategoriesForASINResult.Self) { var newLine = string.Format("{0},{1},{2}{3}", asin, cat.ProductCategoryId, cat.ProductCategoryName, Environment.NewLine); csv.Append(newLine); } } } Thread.Sleep(5000); } try { File.WriteAllText("AmazonCategories.csv", csv.ToString()); } catch (Exception e) { } Console.WriteLine("CHECK THE NEXT PART IF IT FAILED."); return(asinData); }
public static void GetSkuPrice(Dictionary<string, Dictionary<string, float>> skuDict) { // Create a configuration object MarketplaceWebServiceProductsConfig config = new MarketplaceWebServiceProductsConfig(); config.ServiceURL = GlobalConfig.Instance.ServiceURL; // Set other client connection configurations here if needed // Create the client itself MarketplaceWebServiceProducts client = new MarketplaceWebServiceProductsClient(GlobalConfig.Instance.AppName, GlobalConfig.Instance.AppVersion, GlobalConfig.Instance.AccessKey, GlobalConfig.Instance.SecretKey, config); MarketplaceWebServiceProductsSample sample = new MarketplaceWebServiceProductsSample(client, GlobalConfig.Instance.SellerId, "", GlobalConfig.Instance.MarketplaceId); // Uncomment the operation you'd like to test here // TODO: Modify the request created in the Invoke method to be valid try { //*** todo: ������Ҫ��list����Ƭ��ÿ��20�� List<string> skuList = new List<string>(skuDict.Keys); IMWSResponse response = null; int count = GlobalConfig.Instance.SkuPriceCount; int current_index; for (current_index = 0; current_index < skuList.Count; current_index += count){ int current_count = (current_index + count) > skuList.Count ? skuList.Count - current_index : count; List<string> skuRangeList = skuList.GetRange(current_index, current_count); //{ // // ��ȡ���ﳵ�۸� // response = sample.InvokeGetCompetitivePricingForSKU(skuRangeList); // XmlDocument xmlDocument = new XmlDocument(); // xmlDocument.LoadXml(response.ToXML()); // XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDocument.NameTable); // nsmgr.AddNamespace("mws", xmlDocument.GetElementsByTagName("GetCompetitivePricingForSKUResponse")[0].Attributes["xmlns"].Value); // XmlNodeList xnList = xmlDocument.SelectNodes("//mws:GetCompetitivePricingForSKUResult", nsmgr); // foreach (XmlNode xn in xnList) // { // string competitive_price = xn.SelectSingleNode(".//mws:LandedPrice/mws:Amount", nsmgr).InnerText; // skuDict[xn.Attributes["SellerSKU"].Value].Add("competitive_price", float.Parse(competitive_price)); // } //} // ��ȡ��ǰ��ͼ� { response = sample.InvokeGetLowestOfferListingsForSKU(skuRangeList); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(response.ToXML()); XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDocument.NameTable); nsmgr.AddNamespace("mws", xmlDocument.GetElementsByTagName("GetLowestOfferListingsForSKUResponse")[0].Attributes["xmlns"].Value); XmlNodeList xnList = xmlDocument.SelectNodes("//mws:GetLowestOfferListingsForSKUResult", nsmgr); foreach (XmlNode xn in xnList) { XmlNode target = xn.SelectSingleNode(".//mws:LandedPrice/mws:Amount", nsmgr); if (target != null) { string lowest_price = target.InnerText; skuDict[xn.Attributes["SellerSKU"].Value].Add("lowest_price", float.Parse(lowest_price)); } } } // ��ȡ�ҵļ۸� { response = sample.InvokeGetMyPriceForSKU(skuRangeList); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(response.ToXML()); XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDocument.NameTable); nsmgr.AddNamespace("mws", xmlDocument.GetElementsByTagName("GetMyPriceForSKUResponse")[0].Attributes["xmlns"].Value); XmlNodeList xnList = xmlDocument.SelectNodes("//mws:GetMyPriceForSKUResult", nsmgr); foreach (XmlNode xn in xnList) { XmlNode target = xn.SelectSingleNode(".//mws:LandedPrice/mws:Amount", nsmgr); if (target != null) { string my_price = target.InnerText; skuDict[xn.Attributes["SellerSKU"].Value].Add("my_price", float.Parse(my_price)); } } } // Restore rate: 10 items every second System.Threading.Thread.Sleep(GlobalConfig.Instance.SkuPriceWaitTime); } ////ȡ����� ////*** todo: ��ȡ���ﳵ��sellerId���ж��Լ��Ƿ��������ﳵ ////XmlNodeList xnList = xmlDocument.GetElementsByTagName("GetCompetitivePricingForSKUResult"); //// response = sample.InvokeGetCompetitivePricingForASIN(); //// response = sample.InvokeGetCompetitivePricingForSKU(); //// response = sample.InvokeGetLowestOfferListingsForASIN(); //// response = sample.InvokeGetLowestOfferListingsForSKU(); //// response = sample.InvokeGetMatchingProduct(); //// response = sample.InvokeGetMatchingProductForId(); //// response = sample.InvokeGetMyPriceForASIN(); //// response = sample.InvokeGetMyPriceForSKU(); //// response = sample.InvokeGetProductCategoriesForASIN(); //// response = sample.InvokeGetProductCategoriesForSKU(); //// response = sample.InvokeGetServiceStatus(); //// response = sample.InvokeListMatchingProducts(); //Console.WriteLine("Response:"); //ResponseHeaderMetadata rhmd = response.ResponseHeaderMetadata; //// We recommend logging the request id and timestamp of every call. //Console.WriteLine("RequestId: " + rhmd.RequestId); //Console.WriteLine("Timestamp: " + rhmd.Timestamp); //string responseXml = response.ToXML(); //Console.WriteLine(responseXml); } catch (MarketplaceWebServiceProductsException ex) { // Exception properties are important for diagnostics. ResponseHeaderMetadata rhmd = ex.ResponseHeaderMetadata; Console.WriteLine("Service Exception:"); if(rhmd != null) { Console.WriteLine("RequestId: " + rhmd.RequestId); Console.WriteLine("Timestamp: " + rhmd.Timestamp); } Console.WriteLine("Message: " + ex.Message); Console.WriteLine("StatusCode: " + ex.StatusCode); Console.WriteLine("ErrorCode: " + ex.ErrorCode); Console.WriteLine("ErrorType: " + ex.ErrorType); throw ex; } }
/// <summary> /// Get Product Category For ASIN /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnProductCategoriesSearch_Click(object sender, RoutedEventArgs e) { string SellerId = CommonValue.strMerchantId; string MarketplaceId = CommonValue.strMarketplaceId; string AccessKeyId = CommonValue.strAccessKeyId; string SecretKeyId = CommonValue.strSecretKeyId; string ApplicationVersion = CommonValue.strApplicationVersion; string ApplicationName = CommonValue.strApplicationName; string MWSAuthToken = CommonValue.strMWSAuthToken; string strbuff = string.Empty; MarketplaceWebServiceProductsConfig config = new MarketplaceWebServiceProductsConfig(); config.ServiceURL = CommonValue.strServiceURL; MarketplaceWebServiceProductsClient client = new MarketplaceWebServiceProductsClient( ApplicationName, ApplicationVersion, AccessKeyId, SecretKeyId, config); GetProductCategoriesForASINRequest request = new GetProductCategoriesForASINRequest(); request.SellerId = SellerId; request.MarketplaceId = MarketplaceId; request.ASIN = txtProductCategoriesSearchValue.Text.ToString().Trim(); GetProductCategoriesForASINResponse response = client.GetProductCategoriesForASIN(request); if (response.IsSetGetProductCategoriesForASINResult()) { GetProductCategoriesForASINResult getProductCategoriesForASINResult = response.GetProductCategoriesForASINResult; List<Categories> selfList = getProductCategoriesForASINResult.Self; foreach (Categories self in selfList) { strbuff += "カテゴリ名:" + self.ProductCategoryName + System.Environment.NewLine; } txtProductCategoriesResult.Text = strbuff; } }
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; }