Amazon WS, REST, and PHP problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
konstantin
Forum Newbie
Posts: 9
Joined: Tue Mar 21, 2006 1:28 pm

Amazon WS, REST, and PHP problem

Post by konstantin »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


all i need is to perform ItemLookup for a book and display its details. the rpoblem is, i don't know how to send the request and handle the response from Amazon WS.

i tried:

Code: Select all

$url = 'http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=[ ..........]&Operation=ItemLookup&IdType=ASIN&ItemId=0130319996&ResponseGroup=Medium,OfferFull';

$xml = file_get_contents($url);

and get an error right away:

Code: Select all

Warning: file_get_contents(http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=[ .............]&Operation=ItemLookup&IdType=ASIN&ItemId=0130319996&ResponseGroup=Medium,OfferFull) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 500 Server Error in c:\htdocs\phpflash\untitled-6.php on line 4
using PHP 5, and i do have allow_url_fopen ENABLED in the php.ini.

simplexml_load_file() works if i open an actual file but wouldn't handle the Amazon response.

Code: Select all

Warning: xml_parser_create() [function.xml-parser-create]: unsupported source encoding "http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=[ ...]&Operation=ItemLookup&IdType=ASIN&ItemId=0130319996&ResponseGroup=Medium,OfferFull" in c:\htdocs\phpflash\untitled-6.php on line 6

is there a way to figure out if Amazon's response is OK? i use the standard request Amazon suggests on their site.

thanks.


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

[feyd@home]>php -r "var_dump(file_get_contents('http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=[ ..........]&Operation=ItemLookup&IdType=ASIN&ItemId=0130319996&ResponseGroup=Medium,OfferFull'));"
PHP Warning:  file_get_contents(http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=[ ..........]&Operation=ItemLookup&IdType=ASIN&ItemId=0130319996&ResponseGroup=Medium,OfferFull): failed to open stream: HTTP request failed! HTTP/1.1 500 Server Error in Command line code on line 1

Warning: file_get_contents(http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=[ ..........]&Operation=ItemLookup&IdType=ASIN&ItemId=0130319996&ResponseGroup=Medium,OfferFull): failed to open stream: HTTP request failed! HTTP/1.1 500 Server Error in Command line code on line 1
bool(false)

[feyd@home]>php -r "var_dump(file_get_contents('http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=[..........]&Operation=ItemLookup&IdType=ASIN&ItemId=0130319996&ResponseGroup=Medium,OfferFull'));"
string(857) "<?xml version="1.0" encoding="UTF-8"?><ItemLookupResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2005-10-05"><OperationRequest><HTTPHeaders><Header Name="UserAgent"></Header></HTTPHeaders><RequestId>0WP3R4T7WMTRCD5Q3T63</RequestId><Arguments><Argument Name="ResponseGroup" Value="Medium,OfferFull"></Argument><Argument Name="Operation" Value="ItemLookup"></Argument><Argument Name="Service" Value="AWSECommerceService"></Argument><Argument Name="AWSAccessKeyId" Value="[..........]"></Argument><Argument Name="ItemId" Value="0130319996"></Argument><Argument Name="IdType" Value="ASIN"></Argument></Arguments><Errors><Error><Code>AWS.InvalidParameterValue</Code><Message>[..........] is not a valid value for AWSAccessKeyId. Please change this value and retry your request.</Message></Error></Errors></OperationRequest></ItemLookupResponse>"
konstantin
Forum Newbie
Posts: 9
Joined: Tue Mar 21, 2006 1:28 pm

Post by konstantin »

i apologize for not following the rules for posting PHP and Code.

as for the response above, var_dump just tells me that the AWSAccessKeyId is invalid, since i didn't really post it here. but i know for sure that the key i have works.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Your first one errored because of a space mixed in at the access key, maybe the real one has a space too?
konstantin
Forum Newbie
Posts: 9
Joined: Tue Mar 21, 2006 1:28 pm

Post by konstantin »

not only a space somehow ended in the request but also i left the "[" & "]"...... i know...

it works now. thanks a bunch for pointing me in the right direction.
Post Reply