function amazon($Access_Key,$Item_Id="C111WDLL13"){
$allparameter =
"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);
$root = simplexml_load_string($request);
$data = get_object_vars($root);
var_dump($data);
}
----------response-----------
array(2) {
["OperationRequest"]=>
object(SimpleXMLElement)#2 (3) {
["RequestId"]=>
string(36) "ed0f6f43-d6c7-44e1-8747-a4830b69cd52"
["Arguments"]=>
object(SimpleXMLElement)#4 (1) {
["Argument"]=>
array(8) {
[0]=>
object(SimpleXMLElement)#5 (1) {
["@attributes"]=>
array(2) {
["Name"]=>
string(9) "Operation"
["Value"]=>
string(10) "ItemLookup"
}
}
[1]=>
object(SimpleXMLElement)#6 (1) {
["@attributes"]=>
array(2) {
["Name"]=>
string(7) "Service"
["Value"]=>
string(19) "AWSECommerceService"
}
}
[2]=>
object(SimpleXMLElement)#7 (1) {
["@attributes"]=>
array(2) {
["Name"]=>
string(6) "ItemId"
["Value"]=>
string(10) "C111WDLL13"
}
}
[3]=>
object(SimpleXMLElement)#8 (1) {
["@attributes"]=>
array(1) {
["Name"]=>
string(11) "IdType-ASIN"
}
}
[4]=>
object(SimpleXMLElement)#9 (1) {
["@attributes"]=>
array(2) {
["Name"]=>
string(14) "AWSAccessKeyId"
["Value"]=>
string(20) "BLJBJFUKMBEXJMMBBDCB"
}
}
[5]=>
object(SimpleXMLElement)#10 (1) {
["@attributes"]=>
array(2) {
["Name"]=>
string(9) "Timestamp"
["Value"]=>
string(20) "2010-04-20T23:06:43Z"
}
}
[6]=>
object(SimpleXMLElement)#11 (1) {
["@attributes"]=>
array(2) {
["Name"]=>
string(9) "Signature"
["Value"]=>
string(44) "7XAIy4I2A0k56IjSdQ6m2028hx6yTOBtSoS9hBSdj/o="
}
}
[7]=>
object(SimpleXMLElement)#12 (1) {
["@attributes"]=>
array(2) {
["Name"]=>
string(7) "Version"
["Value"]=>
string(10) "2009-01-06"
}
}
}
}
["RequestProcessingTime"]=>
string(18) "0.0192610000000000"
}
["Items"]=>
object(SimpleXMLElement)#3 (2) {
["Request"]=>
object(SimpleXMLElement)#13 (2) {
["IsValid"]=>
string(4) "True"
["ItemLookupRequest"]=>
object(SimpleXMLElement)#15 (10) {
["Condition"]=>
string(3) "New"
["DeliveryMethod"]=>
string(4) "Ship"
["IdType"]=>
string(4) "ASIN"
["MerchantId"]=>
string(6) "Amazon"
["OfferPage"]=>
string(1) "1"
["ItemId"]=>
string(10) "C111WDLL13"
["ResponseGroup"]=>
string(5) "Small"
["ReviewPage"]=>
string(1) "1"
["ReviewSort"]=>
string(15) "-SubmissionDate"
["VariationPage"]=>
string(3) "All"
}
}
["Item"]=>
object(SimpleXMLElement)#14 (4) {
["ASIN"]=>
string(10) "C111WDLL13"
["DetailPageURL"]=>
string(208) "http://www.amazon.com/Homedics-SC-650-Professional-
Doctors-Scale/dp/C111WDLL13%3FSubscriptionId%3DBLJBJFUKMBEXJMMBBDCB
%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative
%3D165953%26creativeASIN%3DC111WDLL13"
["ItemLinks"]=>
object(SimpleXMLElement)#16 (1) {
["ItemLink"]=>
array(7) {
[0]=>
object(SimpleXMLElement)#18 (2) {
["Description"]=>
string(17) "Technical Details"
["URL"]=>
string(218) "http://www.amazon.com/Homedics-SC-650-
Professional-Doctors-Scale/dp/tech-data/C111WDLL13%3FSubscriptionId
%3DBLJBJFUKMBEXJMMBBDCB%26tag%3Dws%26linkCode%3Dxm2%26camp
%3D2025%26creative%3D386001%26creativeASIN%3DC111WDLL13"
}
[1]=>
object(SimpleXMLElement)#19 (2) {
["Description"]=>
string(20) "Add To Baby Registry"
["URL"]=>
string(204) "http://www.amazon.com/gp/registry/baby/add-
item.html%3Fasin.0%3DC111WDLL13%26SubscriptionId%3DBLJBJFUKMBEXJMMBBDCB
%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative
%3D386001%26creativeASIN%3DC111WDLL13"
}
[2]=>
object(SimpleXMLElement)#20 (2) {
["Description"]=>
string(23) "Add To Wedding Registry"
["URL"]=>
string(207) "http://www.amazon.com/gp/registry/wedding/add-
item.html%3Fasin.0%3DC111WDLL13%26SubscriptionId%3DBLJBJFUKMBEXJMMBBDCB
%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative
%3D386001%26creativeASIN%3DC111WDLL13"
}
[3]=>
object(SimpleXMLElement)#21 (2) {
["Description"]=>
string(15) "Add To Wishlist"
["URL"]=>
string(208) "http://www.amazon.com/gp/registry/wishlist/
add-item.html%3Fasin.0%3DC111WDLL13%26SubscriptionId
%3DBLJBJFUKMBEXJMMBBDCB%26tag%3Dws%26linkCode%3Dxm2%26camp
%3D2025%26creative%3D386001%26creativeASIN%3DC111WDLL13"
}
[4]=>
object(SimpleXMLElement)#22 (2) {
["Description"]=>
string(13) "Tell A Friend"
["URL"]=>
string(173) "http://www.amazon.com/gp/pdp/taf/
C111WDLL13%3FSubscriptionId%3DBLJBJFUKMBEXJMMBBDCB%26tag%3Dws
%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN
%3DC111WDLL13"
}
[5]=>
object(SimpleXMLElement)#23 (2) {
["Description"]=>
string(20) "All Customer Reviews"
["URL"]=>
string(177) "http://www.amazon.com/review/product/
C111WDLL13%3FSubscriptionId%3DBLJBJFUKMBEXJMMBBDCB%26tag%3Dws
%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN
%3DC111WDLL13"
}
[6]=>
object(SimpleXMLElement)#24 (2) {
["Description"]=>
string(10) "All Offers"
["URL"]=>
string(179) "http://www.amazon.com/gp/offer-listing/
C111WDLL13%3FSubscriptionId%3DBLJBJFUKMBEXJMMBBDCB%26tag%3Dws
%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN
%3DC111WDLL13"
}
}
}
["ItemAttributes"]=>
object(SimpleXMLElement)#17 (3) {
["Manufacturer"]=>
string(8) "Homedics"
["ProductGroup"]=>
string(2) "CE"
["Title"]=>
string(42) "Homedics SC-650 Professional Doctors Scale"
}
}
}
}
NULL
First of all, this only has one product group. So you can't get
multiple items - all you could do is create an array of one item.
You could get the element out if this one with something like:
$parsed_xml['OperationRequest']->'Items->'Item'->'ItemAttributes'->'ProductGroup'
However, this will only work with this specific hierarchy (and I'm not
100% sure about that - it's untested). Any change, and it will fail
completely.
Chances are you're going to have to parse your XML to get the data you
want reliably. You might want to check the Amazon developer information
to see if someone has code already created to do what you want.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
==================
$access_key = "BLJBJFUKMBEXJMMBBDCB";
$request=anazon($access_key);
var_dump($request);
function anazon($Access_Key,$Item_Id="C111WDLL13"){
$allparameter =
"Service" ."=".
"AWSECommerceService" ."&".
"AWSAccessKeyId" ."=".
$Access_Key ."&".
"Operation" ."=".
"ItemLookup" ."&".
"IdType" ."-".
"ASIN" ."&".
"ItemId" ."=".
$Item_Id ."&".
"Version" ."=".
"2009-01-06"
;
$response = file_get_contents("http://free.apisigning.com/onca/
xml?".$allparameter);
$parsed_xml = simplexml_load_string($response);
$parsed_xml->'OperationRequest'->'Items'->'Item'->'ItemAttributes'-
>'ProductGroup' ;
return $parsed_xml;
}
$parsed_xml['OperationRequest']->Items->Item->ItemAttributes-
>ProductGroup
Yep, that should work better...
Thanks for the correction, Paul. Too late when I wrote that :).
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
==================
thanks, I got something returned from the function. It needs some
adjustment but it works.