TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-30-2008, 01:15 PM   #1 (permalink)
The Contributor
 
oMIKEo's Avatar
 
Join Date: Jan 2008
Location: Leeds
Posts: 52
Thanks: 7
oMIKEo is on a distinguished road
Default 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!
Send a message via MSN to oMIKEo
oMIKEo is offline  
Reply With Quote
Old 01-30-2008, 01:38 PM   #2 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

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
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 01-30-2008, 01:43 PM   #3 (permalink)
The Contributor
 
oMIKEo's Avatar
 
Join Date: Jan 2008
Location: Leeds
Posts: 52
Thanks: 7
oMIKEo is on a distinguished road
Default

Thanks for the fast reply Alan,

That works a treat, I knew I wasn't too far off :)
Send a message via MSN to oMIKEo
oMIKEo is offline  
Reply With Quote
Old 02-08-2008, 09:30 AM   #4 (permalink)
The Contributor
 
oMIKEo's Avatar
 
Join Date: Jan 2008
Location: Leeds
Posts: 52
Thanks: 7
oMIKEo is on a distinguished road
Default

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?
Send a message via MSN to oMIKEo
oMIKEo is offline  
Reply With Quote
Old 02-08-2008, 01:39 PM   #5 (permalink)
The Contributor
 
Gibou's Avatar
 
Join Date: Nov 2007
Location: France, near Paris
Posts: 53
Thanks: 6
Gibou is on a distinguished road
Default

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 ;)
__________________
Wedus project's Website
Send a message via MSN to Gibou
Gibou is offline  
Reply With Quote
Old 02-08-2008, 05:42 PM   #6 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

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
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 02-08-2008, 08:52 PM   #7 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 264
Thanks: 2
TlcAndres is on a distinguished road
Default

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]; 
TlcAndres is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 03:51 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design