Get amazon pictures

Discussion in 'PHP' started by ojsimon, Nov 23, 2007.

  1. #1
    ojsimon, Nov 23, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Do you have permission from Amazon to grab their pictures?
     
    nico_swd, Nov 23, 2007 IP
  3. ojsimon

    ojsimon Active Member

    Messages:
    459
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    No, i will now but it is good for them as i will link the picture to the product page.
    Thanks
     
    ojsimon, Nov 23, 2007 IP
  4. chandubhai

    chandubhai Banned

    Messages:
    556
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Try the amazon api
     
    chandubhai, Nov 24, 2007 IP
  5. ojsimon

    ojsimon Active Member

    Messages:
    459
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #5
    you cant gert them through amazon api
     
    ojsimon, Nov 24, 2007 IP
  6. pluswebdev

    pluswebdev Banned

    Messages:
    205
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I think it is possible to get the pictures using their API
     
    pluswebdev, Nov 24, 2007 IP
  7. ojsimon

    ojsimon Active Member

    Messages:
    459
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #7
    i have searched and cannot find how. please could you tell me
    thanks
     
    ojsimon, Nov 24, 2007 IP
  8. drunnells

    drunnells Peon

    Messages:
    79
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I do something like this to get the cover images of DVDs from Amazon. You do need a Subscriber ID (and an Associate ID if you want to link back to them and make money), see here for more info.

    I am grabbing the item info from a UPC with the following code. You will get some XML that you will need to parse for the SmallImage, MediumImage or LargeImage tags that contain the image url:

    <?
    $amazonAssociateId      = 'my-assocate-id-get-your-own';
    $amazonSubscriberId     = 'my-subscriber-id';
    $amazonWebSrvHost       = 'webservices.amazon.com';
    $amazonWebSrvPath       = '/onca/xml';
    
    $lookupUPC = '097363314479';
    
    $amazonXML=getAmazonMovieInfo($amazonSubscriberId, $amazonAssociateId,$amazonWebSrvHost,$amazonWebSrvPath,$lookupUPC);
    print $amazonXML;
    
    function getAmazonMovieInfo($amazonSubscriberId,$amazonAssociateId,$amazonWebSrvHost,$amazonWebSrvPath,$upc) {
      $query_string="Service=AWSECommerceService"
        . "&SubscriptionId=" . $amazonSubscriberId
        . "&AssociateTag=" . $amazonAssociateId
        . "&Operation=ItemLookup"
        . "&SearchIndex=DVD"
        . "&MerchantId=All&IdType=UPC"
        . "&ItemId=" . $upc
        . "&Condition=All"
        . "&ResponseGroup=Request,Images,Small,ItemAttributes";
      $fetchedXML = getURL($amazonWebSrvHost,$amazonWebSrvPath,$query_string);
      return $fetchedXML;
    }
    
    function getURL($host,$path,$query_string) {
      $toReturn='';
      $toOpen = "http://" . $host . $path . "?" . $query_string;
      $fh = fopen($toOpen, "r");
      if ($fh) {
        while (!feof($fh)) {
          $toReturn .= fgets($fh, 512);
        }
        fclose($fh);
      } else {
        print "Error fetching data from Amazon.com";
      }
      return $toReturn;
    }
    ?>
    PHP:
    This example grabs the movie info xml from amazon based on the UPC of one of favorite movies "Virtuosity" and prints it out. From there you can just use the xml info you need, like the "SmallImage" for the cover art. There is really a ton of stuff you can do with the amazon api, the above was a stripped down version of what i actually use on a dvd site. Hope this helps!
     
    drunnells, Nov 24, 2007 IP