数组不适用于GetCompetitivePricingForASINSample亚马逊MWS PHP

时间:2017-08-13 08:19:50

标签: php amazon-mws

我想从带有ASINS的文本文件(1行中的1个AINS)请求。但我总是得到一个错误。该文件不超过20个ASIN。  我收到错误

  

“警告:rawurlencode()期望参数1为字符串,给定数组   在C:\ xampp \ htdocs \ MarketplaceWebServiceProducts \ Client.php上   1405   或

     

Caught Exception:参数ASINList.ASIN.1验证检查失败:   输入值的外部空格:“”响应状态代码:400   错误代码:InvalidRequest错误类型

$arr = file("asin.txt"); 
    $request = new MarketplaceWebServiceProducts_Model_GetLowestOfferListingsForASINRequest();
    $request->setSellerId(MERCHANT_ID);
    $request->setMarketplaceId(MARKETPLACE_ID);
    $asin_list = new MarketplaceWebServiceProducts_Model_ASINListType();
    $asin_list->setASIN(array($arr));

    $request->setASINList($asin_list);

如果我这样写,就行不通。

$asin_list->setASIN(array($arr[0],$arr[1]));

如果我这样写,那么

$asin_list = new MarketplaceWebServiceProducts_Model_ASINListType();
$asin_list->setASIN(array('0470165057' ,'3944660110'
,'3000383964' ,'3000567852'....

如何从包含1000个ASINS的文件中的列表(1个请求20个ASIN)发出请求?

请帮帮我。 并为我的英语道歉

PS。 来自Asin.txt和print_r

的结果
  

数组([0] => 3944660110 [1] => 3000383964 [2] => 3000400567 [3] =>   3000449523 [4] => 3000489169 [5] => 3000518290 [6] => 3000539069)

asin.txt - 1 Line 1 ASIN

$request = new MarketplaceWebServiceProducts_Model_GetLowestOfferListingsForASINRequest();
$request->setSellerId(MERCHANT_ID);

$arr = file('asin.txt',FILE_IGNORE_NEW_LINES);
$arr_chunks = array_chunk($arr, 20, TRUE);

$request->setMarketplaceId(MARKETPLACE_ID);
$asin_list = new MarketplaceWebServiceProducts_Model_ASINListType();

//$asin_list->setASIN($arr_chunks[0]);
//$request->setASINList($asin_list);

 If $ asin_list-> setASIN ($ arr_chunks [0]);  - Works
 If $ asin_list-> setASIN ($ arr_chunks [1]); - Dont Work

1 个答案:

答案 0 :(得分:0)

您可以使用array_chunk()将1000个asins划分为20个组,例如

$asins_chunks = array_chunk($asins_array, 20, TRUE);

我使用此代码并且有效:

$service = new
 MarketplaceWebServiceProducts_Client($this->aws_access_key,
 $this->aws_secret_access_key, $this->application_name,
 $this->application_version, $this->config);

 $request = new MarketplaceWebServiceProducts_Model_GetLowestOfferListingsForASINRequest();
 $request->setSellerId($this->seller_id);
 $request->setMarketplaceId($this->marketplace_id);

 //requesting product's data for "New" products
 $request->setItemCondition("New");

 //excluding our price data in product api response
 $request->setExcludeMe(TRUE);

 $asin_list = new MarketplaceWebServiceProducts_Model_ASINListType();

 //creating $iec_asins array for returning price data back
 $asins = array("ASIN1","ASIN2","ASIN3");

 $asin_list->setASIN($asins);
 $request->setASINList($asin_list);