TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Amazon web services help (http://www.talkphp.com/absolute-beginners/2143-amazon-web-services-help.html)

oMIKEo 01-30-2008 01:15 PM

Amazon web services help
 
Hi, i'm new to this forum but hope you guys can help me out. I'm trying to get some book information from an ISBN number but i cant get any results to print out. The $request has values and so does the $data array but i cant output any of the information...

Here is what ive got so far:
PHP Code:

<? 
$AWSAccessKeyId 
"MY_CODE_HERE";
$AssociateTag =  "";
$Version =  "";
$Operation =  "ItemLookup";
$SearchIndex "Books";
// ItemID: is a test ISBN number
$ItemId =  "1843151022";
$ResponseGroup "Medium";

$requestfile_get_contents("http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=$AWSAccessKeyId&AssociateTag=$AssociateTag&Version=$Version&Operation=$Operation&ItemId=$ItemId&ResponseGroup=$ResponseGroup"); 

include(
'xml.php'); 
$data XML_unserialize($request); 

$error $data[ItemLookupResponse][Items][Request][Errors][Error][Message]; 
$theAuthor $data[ItemLookupResponse][Items][Item][0][ItemAttributes][Author]; 
$theLabel $data[ItemLookupResponse][Items][Item][0][ItemAttributes][Label]; 
$theBinding $data[ItemLookupResponse][Items][Item][0][ItemAttributes][Binding]; 

if (!
$error) { 
    print (

    Author: '
.$theAuthor.'<br />
    Label: '
.$theLabel.'<br /> 
    Binding: '
.$theBinding.''); 

else
{
    die(
$error);

?>

If anyone could help me get the correct results to display that would be great, thanks guys!

Alan @ CIT 01-30-2008 01:38 PM

Hi oMIKEo, welcome to TalkPHP :-)

The problem with your code looks to be when you are trying to get the values from your $data array.

Your Amazon request only returns a single item so there is no need to specify [0] when accessing the item attributes.

For example, changing that block of your code to:

PHP Code:

$error $data['ItemLookupResponse']['Items']['Request']['Errors']['Error']['Message'];  
$theAuthor $data['ItemLookupResponse']['Items']['Item']['ItemAttributes']['Author'];  
$theLabel $data['ItemLookupResponse']['Items']['Item']['ItemAttributes']['Label'];  
$theBinding $data['ItemLookupResponse']['Items']['Item']['ItemAttributes']['Binding']; 

Will result in the following:

Code:

Author: Louis Fidge
Label: Letts Educational
Binding: Paperback

Hope that helps :-)

oMIKEo 01-30-2008 01:43 PM

Thanks for the fast reply Alan,

That works a treat, I knew I wasn't too far off :)

oMIKEo 02-08-2008 09:30 AM

I'm having a problem with this code now on another machine, im running it locally using the same code but now its not working and i get the following error:

Quote:

Warning: file_get_contents(http://ecs.amazonaws.com/onca/xml?Se...seGroup=Medium) [function.file-get-contents]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\Inetpub\wwwroot\Library\lookup.php on line 52

Fatal error: Maximum execution time of 30 seconds exceeded in C:\Inetpub\wwwroot\Library\lookup.php on line 52
Any ideas why this wouldnt work on another computer?
can your internet connection cause this error?

Gibou 02-08-2008 01:39 PM

file_get_contents is certainly not allowed from local to internet.
Download the xml file, put it in your local folder and try again, changing the url passed to your file_get_contents function.

If a such access could be possible, it would be too easy to hack a website ;)

Alan @ CIT 02-08-2008 05:42 PM

file_get_contents() does support opening of remote files from the local machine - I use it here on my local laptop all the time - just need to make sure that the fopen wrappers are enabled :-)

Mike: Are you able to try using file_get_contents() to open another website/url from the new machine? It looks to me like a firewall or somthing may be blocking it, or perhaps Amazon was just down or on a go slow when you tested it?

Alan

TlcAndres 02-08-2008 08:52 PM

Aside from your data retrieval problems

PHP Code:

$data['ItemLookupResponse']['Items']['Request']['Errors']['Error']['Message']; 

Is a faster alternative to

PHP Code:

$data[ItemLookupResponse][Items][Request][Errors][Error][Message]; 



All times are GMT. The time now is 01:25 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0