亚马逊 MWS PHP 客户端库似乎不完整

Amazon MWS PHP Client Library seems incomplete

我正在尝试开发一个使用 ListMatchingProducts 方法的应用程序。

最终结果将是一个应用程序,该应用程序搜索已在内部库存数据库中的给定产品并将结果呈现给用户,以便他们 select 哪个亚马逊产品与他们的数据库中有一个。

我找到的 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");
     }
  }

坦率地说,"samples" 似乎有点不合时宜。

查看代码,您似乎需要手动设置 marketplaceId,在构造函数中通过关联数组或作为 setter 方法调用。

例如 $request->setMarketplaceId(MARKETPLACE_ID)