2017-08-13 51 views
0

我想用带有ASINS的文本文件(1行1个AINS)请求。但我总是得到一个错误。该文件不超过20个ASIN。 我得到错误数组无法在GetCompetitivePricingForASINSample中工作亚马逊MWS PHP

“警告:rawurlencode()预计参数1是字符串,在C中给出 阵列:\ XAMPP \ htdocs中\ MarketplaceWebServiceProducts \ Client.php上线或

陷入例外:参数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'.... 

我如何从一个文件的请求与列表(1个请求20个ASINs)从文件中有1000 ASINS?

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

PS。从Asin.txt用的print_r

阵列([0] => 3944660110 结果[1] => 3000383964 [2] => 3000400567 [3] => 3000449523 [4] => 3000489169 [5] => 3000518290 [6] => 3000539069)

asin.txt - 1行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 
+0

'$ asin_list-> setASIN($ ARR);'应该工作,假设文件有不到20行(它有7个在你的例如用print_r转储),并且所有元素都是字符串,而不是整数(print_r不会显示var_dump会)。 – Hazzit

回答

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);