MWS是商城網絡服務的縮寫,具體介紹看這里http://docs.developer.amazonservices.com/zh_CN/dev_guide/DG_IfNew.html。MWS就是一組API,提供給開發者調用,實現賣家的數據上傳、獲取報告、庫存、訂單等。上面的貼出來的鏈接里有關於MWS開發者的詳細說明,建議先好好通讀下“程序員開發指南”,先了解下需要怎么去拼接請求地址和必傳參數,否則會走很多彎路。
在構造一個請求MWS的url之前,你必須得有一個賣家ID(merchantId),如果你自己就是賣家,那么就拿你的賣家ID去注冊一個開發者賬號,亞馬遜會給你一個開發者ID、一個訪問秘鑰ID(accessKeyId)和一個訪問秘鑰(secretAccessKey),我們只需要用到3個信息:merchantId、accessKeyId和secretAccessKey。如果賣家是你的朋友,那么同上,由他去注冊開發者賬號,把這3個信息給你即可。如果是第三方開發者(他已經自己注冊了開發者賬號),那么賣家需要拿第三方開發者的賬號進行授權,授權他能訪問賣家賬號,這種情況需要把授權令牌(sellerDevAuthToken)拼接到請求地址中。最后作為開發者,你還得知道賣家的MWS究竟是在哪個國家開的,是在美國,歐洲,還是中國?每個地方對應不同的鏈接地址。
亞馬遜 MWS 文檔 » 程序開發員指南 » 亞馬遜 MWS Scratchpad(測試工具),點開之后有不同國家MWS對應測試鏈接,可以要求把對應的參數輸進去,看下API返回信息對不對。假設我的店開在中國區,那么就到https://developer.amazonservices.com.cn/這里去點開“導航 -> 亞馬遜 MWS Scratchpad(測試工具)”。如果是國外的MWS會慢一些,畢竟傳輸路徑比較長嘛。假如我現在是在北美注冊的賣家賬號,那么點開https://developer.amazonservices.com(等待n秒) -> Amazon MWS Scratchpad -> SellerId填merchantId、AWSAccessKeyId填accessKeyId、Secret Key填secretAccessKey -> 最后選對應API操作后,點擊提交即可。
如果你想下載客戶端代碼,直接點開“API與文檔 -> 報告(隨便點開一個接口即可)-> Java客戶端(選擇你想要的語言)-> download”。下好了代碼直接就拿來主義好了,改改上面的請求字段就可以跑起來了,看一下獲取報告條數的API:
/******************************************************************************* * Copyright 2009 Amazon Services. * Licensed under the Apache License, Version 2.0 (the "License"); * * You may not use this file except in compliance with the License. * You may obtain a copy of the License at: http://aws.amazon.com/apache2.0 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * ***************************************************************************** * * Marketplace Web Service Java Library * API Version: 2009-01-01 * Generated: Wed Feb 18 13:28:48 PST 2009 * */ package com.amazonaws.mws.samples; import java.util.List; import java.util.ArrayList; import com.amazonaws.mws.*; import com.amazonaws.mws.model.*; import com.amazonaws.mws.mock.MarketplaceWebServiceMock; /** * * Get Report Count Samples * * */ public class GetReportCountSample { /** * Just add a few required parameters, and try the service * Get Report Count functionality * * @param args unused */ public static void main(String... args) { /************************************************************************ * Access Key ID and Secret Access Key ID, obtained from: * http://aws.amazon.com ***********************************************************************/ final String accessKeyId = "WWWWWWLLLLLLFFFFFFFF"; final String secretAccessKey = "WWWWWWLLLLLLFFFFFFFFWWWWWWLLLLLLFFFFFFFF"; final String appName = "AmazonJavascriptScratchpad"; final String appVersion = "1.0"; MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig(); /************************************************************************ * Uncomment to set the appropriate MWS endpoint. ************************************************************************/ // US config.setServiceURL("https://mws.amazonservices.com/"); // UK // config.setServiceURL("https://mws.amazonservices.co.uk/"); // Germany // config.setServiceURL("https://mws.amazonservices.de/"); // France // config.setServiceURL("https://mws.amazonservices.fr/"); // Italy // config.setServiceURL("https://mws.amazonservices.it/"); // Japan // config.setServiceURL("https://mws.amazonservices.jp/"); // China // config.setServiceURL("https://mws.amazonservices.com.cn/"); // Canada // config.setServiceURL("https://mws.amazonservices.ca/"); // India // config.setServiceURL("https://mws.amazonservices.in/"); /************************************************************************ * The argument (35) set below is the number of threads client should * spawn for processing. ***********************************************************************/ config.setMaxAsyncThreads(35); /************************************************************************ * You can also try advanced configuration options. Available options are: * * - Signature Version * - Proxy Host and Proxy Port * - User Agent String to be sent to Marketplace Web Service * ***********************************************************************/ /************************************************************************ * Instantiate Http Client Implementation of Marketplace Web Service ***********************************************************************/ MarketplaceWebService service = new MarketplaceWebServiceClient( accessKeyId, secretAccessKey, appName, appVersion, config); /************************************************************************ * Uncomment to try out Mock Service that simulates Marketplace Web Service * responses without calling Marketplace Web Service service. * * Responses are loaded from local XML files. You can tweak XML files to * experiment with various outputs during development * * XML files available under com/amazonaws/mws/mock tree * ***********************************************************************/ // MarketplaceWebService service = new MarketplaceWebServiceMock(); /************************************************************************ * Setup request parameters and uncomment invoke to try out * sample for Get Report Count ***********************************************************************/ /************************************************************************ * Marketplace and Merchant IDs are required parameters for all * Marketplace Web Service calls. ***********************************************************************/ final String merchantId = "WWWWLLLLLFFFFF"; final String sellerDevAuthToken = "<Merchant Developer MWS Auth Token>"; GetReportCountRequest request = new GetReportCountRequest(); request.setMerchant( merchantId ); //request.setMWSAuthToken(sellerDevAuthToken); // @TODO: set request parameters here invokeGetReportCount(service, request); } /** * Get Report Count request sample * returns a count of reports matching your criteria; * by default, the number of reports generated in the last 90 days, * regardless of acknowledgement status * * @param service instance of MarketplaceWebService service * @param request Action to invoke */ public static void invokeGetReportCount(MarketplaceWebService service, GetReportCountRequest request) { try { GetReportCountResponse response = service.getReportCount(request); System.out.println ("GetReportCount Action Response"); System.out.println ("============================================================================="); System.out.println (); System.out.print(" GetReportCountResponse"); System.out.println(); if (response.isSetGetReportCountResult()) { System.out.print(" GetReportCountResult"); System.out.println(); GetReportCountResult getReportCountResult = response.getGetReportCountResult(); if (getReportCountResult.isSetCount()) { System.out.print(" Count"); System.out.println(); System.out.print(" " + getReportCountResult.getCount()); System.out.println(); } } if (response.isSetResponseMetadata()) { System.out.print(" ResponseMetadata"); System.out.println(); ResponseMetadata responseMetadata = response.getResponseMetadata(); if (responseMetadata.isSetRequestId()) { System.out.print(" RequestId"); System.out.println(); System.out.print(" " + responseMetadata.getRequestId()); System.out.println(); } } System.out.println(); System.out.println(response.getResponseHeaderMetadata()); System.out.println(); } catch (MarketplaceWebServiceException ex) { System.out.println("Caught Exception: " + ex.getMessage()); System.out.println("Response Status Code: " + ex.getStatusCode()); System.out.println("Error Code: " + ex.getErrorCode()); System.out.println("Error Type: " + ex.getErrorType()); System.out.println("Request ID: " + ex.getRequestId()); System.out.print("XML: " + ex.getXML()); System.out.println("ResponseHeaderMetadata: " + ex.getResponseHeaderMetadata()); } } }
跑完控制台輸出成功日志:
GetReportCount Action Response ============================================================================= GetReportCountResponse GetReportCountResult Count 1593 ResponseMetadata RequestId ae847abb-6335-4ec3-904c-b3fdbd999979 requestId : ae847abb-6335-4ec3-904c-b3fdbd999979 responseContext : bu7253H8xUoTt/yMP7gsP5osYa5dLIQ0Av+i7ENQwKBd14/ZhdEIw6yQW+2kan0HwujlUmeuaR8= timestamp : 2018-07-16T07:57:35.453Z