[Web4lib] Amazon image function

Glen Wiley gsw55 at cornell.edu
Tue Jan 29 16:39:15 EST 2008


Hi everyone,

I know people have discussed Amazon book images issues on this listserv 
before, but here is a more technical question.

I'm using this php code to pull Amazon book cover images into a new book 
list.  It does work, but I wondered if anyone had a suggestion about how 
to do it better.  We aren't getting very many successful image displays 
because many of them time out or error out.  So out of 100 new books, I 
get 10 images appear.  Any suggestions here?

function RESTQuery($isbn){
   //1VE157GS2Z7SMVS61G02
   $base         = 'http://ecs.amazonaws.com/onca/xml';
   $query_string = '';
   
   $params = array(
       'ItemId' => "$isbn",
       'IdType' => "ASIN",
       'Service' => 'AWSECommerceService',
       'Operation' => 'ItemLookup',
       #'SearchIndex' => 'Books',
       #'sort'  => '+relevance',
       'ResponseGroup'  => 'Images',
       'AWSAccessKeyId' => '1VE157GS2Z7SMVS61G02',
       'Style' =>    "XML",
       'XMLEscaping' => "Double",
       'Version'    => "2007-07-16"
   );
   
   foreach ($params as $key => $value) {
       $query_string .= "$key=" . urlencode($value) . "&";
   }
   
   $url = "$base?$query_string";  
   
   $xmlstr = file_get_contents($url);
   if($xmlstr == "") return;
   $xml = new SimpleXMLElement($xmlstr);
   #return $xml->asXml();
   $imageURL = $xml->Items->Item->MediumImage->URL;
   
   if($imageURL != ""){
       return "<a href=\"http://www.amazon.com\"><img src=\"$imageURL\" 
/></a>";    
   }
   else{
       return "";
   }
}


--Glen

 

------------------------------------------------------------------------

Glen Wiley
Metadata Librarian

Metadata Services <http://metadata.library.cornell.edu/>

107E Olin Library
Cornell University
Ithaca, NY 14853/
/gsw55 at cornell.edu <mailto:gsw55 at cornell.edu>
607-254-5145
 

--/ Our Vision is to be internationally recognized and respected as a 
center of metadata expertise. --/

 



More information about the Web4lib mailing list