捕获异常:在amazon命令api中拒绝访问

时间:2016-04-22 07:55:24

标签: php amazon-web-services

我创建了亚马逊卖家帐户,我已经注册了mws(市场网络服务),我得到了所有密钥,如密钥,访问密钥等。 现在我首先下载了亚马逊订单api它附带了一组文件。 在.config.inc.php下,我提供了所有凭据,并且他在示例文件夹下提供了一些示例代码,首先我打开GetOrderSample.php并在浏览器中运行文件后将服务URL取消注释为$serviceUrl = "https://mws.amazonservices.com/Orders/2013-09-01";它说:

  

“捕获异常:拒绝访问响应状态码:401错误代码:AccessDenied错误类型:发件人请求ID:606e9ead-fb70-4a60-a795-4fc601421c65 XML:发件人AccessDenied”

请帮我解决这个问题,很长一段时间才停留在这个地方。 这是GetOrderSample.php的文件代码,

<?php
      /*******************************************************************************
       * Copyright 2009-2015 Amazon Services. All Rights Reserved.
       * 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.
       *******************************************************************************
       * PHP Version 5
       * @category Amazon
       * @package  Marketplace Web Service Orders
       * @version  2013-09-01
       * Library Version: 2015-09-24
       * Generated: Fri Sep 25 20:06:28 GMT 2015
       */

      /**
       * Get Order Sample
       */

      require_once('.config.inc.php');

      /************************************************************************
       * Instantiate Implementation of MarketplaceWebServiceOrders
       *
       * AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY constants
       * are defined in the .config.inc.php located in the same
       * directory as this sample
       ***********************************************************************/
      // More endpoints are listed in the MWS Developer Guide
      // North America:
      $serviceUrl = "https://mws.amazonservices.com/Orders/2013-09-01";
      // Europe
      //$serviceUrl = "https://mws-eu.amazonservices.com/Orders/2013-09-01";
      // Japan
      //$serviceUrl = "https://mws.amazonservices.jp/Orders/2013-09-01";
      // China
      //$serviceUrl = "https://mws.amazonservices.com.cn/Orders/2013-09-01";


       $config = array (
         'ServiceURL' => $serviceUrl,
         'ProxyHost' => null,
         'ProxyPort' => -1,
         'ProxyUsername' => null,
         'ProxyPassword' => null,
         'MaxErrorRetry' => 3,
       );

       $service = new MarketplaceWebServiceOrders_Client(
              AWS_ACCESS_KEY_ID,
              AWS_SECRET_ACCESS_KEY,
              APPLICATION_NAME,
              APPLICATION_VERSION,
              $config);

      /************************************************************************
       * Uncomment to try out Mock Service that simulates MarketplaceWebServiceOrders
       * responses without calling MarketplaceWebServiceOrders service.
       *
       * Responses are loaded from local XML files. You can tweak XML files to
       * experiment with various outputs during development
       *
       * XML files available under MarketplaceWebServiceOrders/Mock tree
       *
       ***********************************************************************/
       // $service = new MarketplaceWebServiceOrders_Mock();

      /************************************************************************
       * Setup request parameters and uncomment invoke to try out
       * sample for Get Order Action
       ***********************************************************************/
       // @TODO: set request. Action can be passed as MarketplaceWebServiceOrders_Model_GetOrder
       $request = new MarketplaceWebServiceOrders_Model_GetOrderRequest();
       $request->setSellerId(MERCHANT_ID);
       // object or array of parameters
       invokeGetOrder($service, $request);

      /**
        * Get Get Order Action Sample
        * Gets competitive pricing and related information for a product identified by
        * the MarketplaceId and ASIN.
        *
        * @param MarketplaceWebServiceOrders_Interface $service instance of MarketplaceWebServiceOrders_Interface
        * @param mixed $request MarketplaceWebServiceOrders_Model_GetOrder or array of parameters
        */

        function invokeGetOrder(MarketplaceWebServiceOrders_Interface $service, $request)
        {
            try {
              $response = $service->GetOrder($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 (MarketplaceWebServiceOrders_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");
           }
       }

2 个答案:

答案 0 :(得分:0)

是的,它解决了,我使用北美服务网址,我不得不使用欧洲服务网址....它应该是印度的。

$serviceUrl = "mws-eu.amazonservices.com/Orders/2013-09-01";

答案 1 :(得分:0)

印度亚马逊MWS终点:https://mws.amazonservices.in

了解更多信息read