我正在亚马逊MWS API for PHP上测试示例API。当我在GetMyPriceForASIN示例中运行代码时,即使出现错误响应也不会返回任何响应。
$ret = 'ASINList.ASIN.0.=000001ASS&ASINList.ASIN.1.=B00002YHY&ASINList.ASIN.2.=B01112Z4VW';
$request = new MarketplaceWebServiceProducts_Model_GetMyPriceForASINRequest();
$request->setSellerId(MERCHANT_ID);
$request->setASINList($ret);
invokeGetMyPriceForASIN($service, $request);
function invokeGetMyPriceForASIN(MarketplaceWebServiceProducts_Interface $service, $request){
try {
$response = $service->GetMyPriceForASIN($request);
$dom1 = new DOMDocument();
$dom1->loadXML($response->toXML());
$dom1->preserveWhiteSpace = false;
$dom1->formatOutput = true;
echo $dom1->saveXML();
} catch (MarketplaceWebServiceProducts_Exception $ex1) {
echo("Caught Exception: " . $ex1->getMessage() . "\n");
echo("Response Status Code: " . $ex->getStatusCode() . "\n");
echo("Error Code: " . $ex1->getErrorCode() . "\n");
echo("Error Type: " . $ex1->getErrorType() . "\n");
echo("Request ID: " . $ex1->getRequestId() . "\n");
echo("XML: " . $ex1->getXML() . "\n");
echo("ResponseHeaderMetadata: " . $ex1->getResponseHeaderMetadata() . "\n");
}
}
当我尝试自己调试时,我一直被困住,直到这组代码
public function getMyPriceForASIN($request){
if (!($request instanceof MarketplaceWebServiceProducts_Model_GetMyPriceForASINRequest)) {
require_once (dirname(__FILE__) . '/Model/GetMyPriceForASINRequest.php');
$request = new MarketplaceWebServiceProducts_Model_GetMyPriceForASINRequest($request);
}
$parameters = $request->toQueryParameterArray();
$parameters['Action'] = 'GetMyPriceForASIN';
$httpResponse = $this->_invoke($parameters);
require_once (dirname(__FILE__) . '/Model/GetMyPriceForASINResponse.php');
$response = MarketplaceWebServiceProducts_Model_GetMyPriceForASINResponse::fromXML($httpResponse['ResponseBody']);
$response->setResponseHeaderMetadata($httpResponse['ResponseHeaderMetadata']);
return $response;
}
这段代码我遇到了错误
$parameters = $request->toQueryParameterArray();
它不返回任何数组,我不知道在哪里找到该函数。 我也想知道可能是我的ASIN列表格式错了,这就是格式。
ASINList.ASIN.0.=000001ASS&ASINList.ASIN.1.=B00002YHY&ASINList.ASIN.2.=B01112Z4VW
答案 0 :(得分:0)
我终于在我的ASIN列表格式中找到了答案,这是错误的。我使用这些代码正确格式化我的ASIN列表
$asin_list = new MarketplaceWebServiceProducts_Model_ASINListType();
$ret = $asin_list->setASIN($xml_arr);
答案 1 :(得分:0)
我认为您需要在$request->setASINList($ret);
require_once "MarketplaceWebServiceProducts_Model_GetMyPriceForASINRequest";
$asin_list = new MarketplaceWebServiceProducts_Model_ASINListType();
$asin_list->setASIN($asins_array);