今天公司要調整抓取fba的fee的爬蟲,改用調用接口的方式,按照官方的demo調了一天終於搞定了,特意分享一下php
<?phpdom
require_once('.config.inc.php');ide
$serviceUrl = "https://mws.amazonservices.com/Products/2011-10-01";ui
$config = array (
'ServiceURL' => $serviceUrl,
'ProxyHost' => null,
'ProxyPort' => -1,
'ProxyUsername' => null,
'ProxyPassword' => null,
'MaxErrorRetry' => 3,
);this
$service = new MarketplaceWebServiceProducts_Client(
AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY,
APPLICATION_NAME,
APPLICATION_VERSION,
$config);code
//First we set up all the list variables
$FeesEstimateRequest = new MarketplaceWebServiceProducts_Model_FeesEstimateRequest();
$FeesEstimateRequest->setMarketplaceId('ATVPDKIKX0DER'); // Amazon.com marketplace id
$FeesEstimateRequest->setIdType('SellerSKU'); // IdType values: ASIN, SellerSKU, SellerSKU in your case
$FeesEstimateRequest->setIdValue('XXXXXXXXXX'); // The value of the id you have entered
$FeesEstimateRequest->setIdentifier('request1'); // A identifier for the item you have requested, this is for your own use
$FeesEstimateRequest->setIsAmazonFulfilled(FALSE); // Fullfilled by Amazon? true if the offer is fulfilled by Amazon. orm
//To set up the $PriceToEstimateFees object we need two instances of the object MarketplaceWebServiceProducts_Model_MoneyType
//@ set up for both cases: Listing Price and Shipping Price
//New object MoneyType, setting up the currency and amount for listing price
$MoneyTypeListingPrice = new MarketplaceWebServiceProducts_Model_MoneyType();
$MoneyTypeListingPrice->setCurrencyCode('USD'); // String, the currency code of the price : USD in this example for amazon.com marketplace
$MoneyTypeListingPrice->setAmount('0.00'); // String, the price of the item 接口
//New object MoneyType, setting up the currency and amount for shipping price
$MoneyTypeShipping = new MarketplaceWebServiceProducts_Model_MoneyType();
$MoneyTypeShipping->setCurrencyCode('USD'); // String, the currency code of the price : USD in this example for amazon.com marketplace
$MoneyTypeShipping->setAmount('0.00'); // String, the price of the item ip
//Setting up the prices: Listing Price and Shipping Price
$PriceToEstimateFees = new MarketplaceWebServiceProducts_Model_PriceToEstimateFees();
$PriceToEstimateFees->setListingPrice($MoneyTypeListingPrice);
$PriceToEstimateFees->setShipping($MoneyTypeShipping);get
//Finally setting up the $PriceToEstimateFees object to the $FeesEstimateRequest object
$FeesEstimateRequest->setPriceToEstimateFees($PriceToEstimateFees); // The product price that the fee estimate is based on.
//setting up the final required parameter in the $FeesEstimateRequestList object
$FeesEstimateRequestList = new MarketplaceWebServiceProducts_Model_FeesEstimateRequestList();
$FeesEstimateRequestList->setFeesEstimateRequest($FeesEstimateRequest);
// Last step : sending the $FeesEstimateRequestList object into $request
$request = new MarketplaceWebServiceProducts_Model_GetMyFeesEstimateRequest();
$request->setSellerId(MERCHANT_ID);
$request->setFeesEstimateRequestList($FeesEstimateRequestList);
// object or array of parameters
invokeGetMyFeesEstimate($service, $request);
function invokeGetMyFeesEstimate(MarketplaceWebServiceProducts_Interface $service, $request)
{
try {
$response = $service->GetMyFeesEstimate($request);
echo ("Service Response\n");
echo ("=============================================================================\n");
$dom = new DOMDocument();
$dom->loadXML($response->toXML());
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
echo $dom->saveXML();
echo("ResponseHeaderMetadata: " . $response->getResponseHeaderMetadata() . "\n");
} catch (MarketplaceWebServiceProducts_Exception $ex) { echo("Caught Exception: " . $ex->getMessage() . "\n"); echo("Response Status Code: " . $ex->getStatusCode() . "\n"); echo("Error Code: " . $ex->getErrorCode() . "\n"); echo("Error Type: " . $ex->getErrorType() . "\n"); echo("Request ID: " . $ex->getRequestId() . "\n"); echo("XML: " . $ex->getXML() . "\n"); echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n"); } }