[Web4lib] Amazon image function

Roy Tennant tennantr at oclc.org
Tue Jan 29 16:46:35 EST 2008


While I will not go so far as to call this posting off-topic (it isn't),
that doesn't mean that there is not a more appropriate place to ask a coding
question. When I need help with code, I go to Code4Lib:

http://dewey.library.nd.edu/mailing-lists/code4lib/

That's where all the serious geeks hang out, and therefore you're more
likely to be successful there.
Roy


On 1/29/08 1:39 PM, "Glen Wiley" <gsw55 at cornell.edu> wrote:

> 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. --/
> 
>  
> 
> _______________________________________________
> Web4lib mailing list
> Web4lib at webjunction.org
> http://lists.webjunction.org/web4lib/

-- 




More information about the Web4lib mailing list