I went through the trouble to put the xml object into an array so I could get the value
of Error and Code in the if/else clause. I have set the product ASIN to an incorrect number to get an error. It should put a value in the xml array.
This is the error
Notice: Undefined index: Code in /Library/WebServer/Documents/lexsource15.php on line 39
Notice: Undefined index: Message in /Library/WebServer/Documents/lexsource15.php on line 40 in the else
//$Item_Id = 'B000BUR1CY';
$Item_Id = 'B000BUR1';
$allparameter =
//ASSOCIATE TAG
"Service" ."=". "AWSECommerceService" ."&".
"AWSAccessKeyId" ."=". $Access_Key ."&".
"Operation" ."=". "ItemLookup" ."&".
"IdType" ."-". "ASIN" ."&".
"ItemId" ."=". $Item_Id ."&".
"Version" ."=". "2009-01-06"
;
$request = file_get_contents("http://free.apisigning.com/onca/xml?".$allparameter);
$result = simplexml_load_string($request);
$xmlArr=objectsIntoArray($result);
print_r($xmlArr);
if(in_array(NEEDLE, $xmlArr)){
$xmlObj= $result->Items->Item->ItemAttributes->ProductGroup;
$category= (string) $xmlObj;
}else{
print_r($xmlArr["Code"]);
print_r($xmlArr["Message"]);
}
function objectsIntoArray($arrObjData, $arrSkipIndices=array())
{
$arrData = array();
if (is_object($arrObjData)){
$arrObjData=get_object_vars($arrObjData);
}
if (is_array($arrObjData)) {
foreach ($arrObjData as $index=>$value ){
if (is_object($value ) || is_array($value)){
$value = objectsIntoArray($value, $arrSkipIndices);
}
if (in_array($index,$arrSkipIndices)){
continue;
}
$arrData[$index]=$value;
}
}
return $arrData;
}
I enclose the print_r of $xmlArr
It doesn't look a whole lot different than it did before the function objectsIntoArray()
I need some advice. Thanks,
Array ( [OperationRequest] => Array ( [RequestId] => 16a176b2-c8c8-4a2f-a97a-e65538b1eebb [Arguments] => Array ( [Argument] => Array ( [0] => Array ( [@attributes] => Array ( [Name] => Operation [Value] => ItemLookup ) ) [1] => Array ( [@attributes] => Array ( [Name] => Service [Value] => AWSECommerceService ) ) [2] => Array ( [@attributes] => Array ( [Name] => Signature [Value] => YfSXo0uor+6lE/6+oNkS/c+hgZBsihiKlfo64p78y2A= ) ) [3] => Array ( [@attributes] => Array ( [Name] => Version [Value] => 2009-01-06 ) ) [4] => Array ( [@attributes] => Array ( [Name] => ItemId [Value] => B000BUR1 ) ) [5] => Array ( [@attributes] => Array ( [Name] => IdType-ASIN ) ) [6] => Array ( [@attributes] => Array ( [Name] => AWSAccessKeyId [Value] =>AIETJLADYILLAACBAABCS) ) [7] => Array ( [@attributes] => Array ( [Name] => Timestamp [Value] => 2010-05-14T23:59:04Z ) ) ) ) [RequestProcessingTime] => 0.0043580000000000 ) [Items] => Array ( [Request] => Array ( [IsValid] => True [ItemLookupRequest] => Array ( [Condition] => New [DeliveryMethod] => Ship [IdType] => ASIN [MerchantId] => Amazon [OfferPage] => 1 [ItemId] => B000BUR1 [ResponseGroup] => Small [ReviewPage] => 1 [ReviewSort] => -SubmissionDate [VariationPage] => All ) [Errors] => Array ( [Error] => Array (
=> AWS.InvalidParameterValue [Message] => B000BUR1 is not a valid value for ItemId. Please change this value and retry your request. ) ) ) )