我正在尝试开发一个使用ListMatchingProducts
方法的应用程序。
最终结果将是一个应用程序,它搜索已存在于内部库存数据库中的给定产品,并将结果显示给用户,以便他们可以选择哪个Amazon产品与其数据库中的产品正确匹配。 / p>
我找到的PHP客户端库链接了here。
我已正确编辑Samples / .config.inc.php(我已删除评论并修改了敏感信息):
define('AWS_ACCESS_KEY_ID', '/*REDACTED BUT SET CORRECTLY*/');
define('AWS_SECRET_ACCESS_KEY', '/*REDACTED BUT SET CORRECTLY*/');
define('APPLICATION_NAME', 'STES_MWS_STOCK_SYNC_APP');
define('APPLICATION_VERSION', '0.1');
define ('MERCHANT_ID', '/*REDACTED BUT SET CORRECTLY*/');
define ('MARKETPLACE_ID', 'A1F83G8C2ARO7P'); // Marketplace ID for the UK
我还取消了Samples / ListMatchingProductsSample.php中相应的行:
$serviceUrl = "https://mws-eu.amazonservices.com/Products/2011-10-01";
然而,执行此脚本会产生以下消息(我已经编辑了一些XML响应):
Caught Exception: Required parameter MarketplaceId not found
Response Status Code: 400
Error Code: MissingParameter
Error Type: Sender
Request ID: /*REDACTED UUID-LIKE STRING*/
XML: <?xml version="1.0"?>
<ErrorResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01"><Error><Type>Sender</Type><Code>MissingParameter</Code><Message>Required parameter MarketplaceId not found</Message><Detail/></Error><RequestID>/*REDACTED UUID-LIKE STRING*/</RequestID></ErrorResponse>
ResponseHeaderMetadata: RequestId: /*REDACTED UUID-LIKE STRING*/, ResponseContext: /*REDACTED LONG STRING*/, Timestamp: 2017-04-24T13:25:33.533Z, Quota Max: 719.0, Quota Remaining: 719.0, Quota Resets At: 2017-04-24T14:03:00.000Z
由于此客户端库自2011年以来一直存在,我发现很难相信这实际上是代码中的错误代码,但我似乎无法找到我出错的地方;扫描代码我找不到对Samples / .config.inc.php中定义的MARKETPLACE_ID
常量的引用
在我编写自己的客户端库之前(我希望避免使用这么简单的应用程序)我想知道:
- 编辑 -
为了完整性,这里是我试图运行的代码 - 示例代码 - 减去注释:
require_once('.config.inc.php');
$serviceUrl = "https://mws-eu.amazonservices.com/Products/2011-10-01";
$config = array (
'ServiceURL' => $serviceUrl,
'ProxyHost' => null,
'ProxyPort' => -1,
'ProxyUsername' => null,
'ProxyPassword' => null,
'MaxErrorRetry' => 3,
);
$service = new MarketplaceWebServiceProducts_Client(
AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY,
APPLICATION_NAME,
APPLICATION_VERSION,
$config);
$request = new MarketplaceWebServiceProducts_Model_ListMatchingProductsRequest();
$request->setSellerId(MERCHANT_ID);
invokeListMatchingProducts($service, $request);
function invokeListMatchingProducts(MarketplaceWebServiceProducts_Interface $service, $request)
{
try {
$response = $service->ListMatchingProducts($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");
}
}
答案 0 :(得分:2)
坦率地说,似乎“样本”有点勉强。
查看代码,您可能需要手动设置marketplaceId,无论是在构造函数中通过关联数组还是作为setter方法调用。
e.g。
$request->setMarketplaceId(MARKETPLACE_ID)