using php on website
WhiteOakBooks BookSite Forums
Home       Members    Calendar    Who's On
Welcome Guest ( Login | Register )
        



using php on website Expand / Collapse
Author
Message
Posted 12/13/2013 12:38:26 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: WOB User
Last Login: 3/14/2016 2:22:07 PM
Posts: 47, Visits: 120
Hello,

I'm interested in experimenting with php a bit. I'm trying to create a textbook buyback calculator for our site using the Amazon API. I've used javascript before, but I haven't ever (successfully) added php to anything. I realize that I can't get a full php tutorial on our board here, but I thought you might get me started. I found a script for getting basic product information from Amazon and I'd like to run it on my site and then play around with Amazon's many possible variables. How might I get started?

The code looks like this, and I've put in my credentials and uploaded "amazon_api_class.php" to my site:


require_once 'aws_signed_request.php';

class AmazonProductAPI
{

private $public_key = "YOUR AMAZON ACCESS KEY ID";
private $private_key = "YOUR AMAZON SECRET KEY";

/* 'Associate Tag' now required, effective from 25th Oct. 2011 */
private $associate_tag = "YOUR AMAZON ASSOCIATE TAG";

const MUSIC = "Music";
const DVD = "DVD";
const GAMES = "VideoGames";

private function verifyXmlResponse($response)
{
if ($response === False)
{
throw new Exception("Could not connect to Amazon");
}
else
{
if (isset($response->Items->Item->ItemAttributes->Title))
{
return ($response);
}
else
{
throw new Exception("Invalid xml response.");
}
}
}

private function queryAmazon($parameters)
{
return aws_signed_request("com",
$parameters,
$this->public_key,
$this->private_key,
$this->associate_tag);
}

public function searchProducts($search,$category,$searchType="UPC")
{
$allowedTypes = array("UPC", "TITLE", "ARTIST", "KEYWORD");
$allowedCategories = array("Music", "DVD", "VideoGames");

switch($searchType)
{
case "UPC" :
$parameters = array("Operation" => "ItemLookup",
"ItemId" => $search,
"SearchIndex" => $category,
"IdType" => "UPC",
"ResponseGroup" => "Medium");
break;

case "TITLE" :
$parameters = array("Operation" => "ItemSearch",
"Title" => $search,
"SearchIndex" => $category,
"ResponseGroup" => "Medium");
break;

}

$xml_response = $this->queryAmazon($parameters);

return $this->verifyXmlResponse($xml_response);

}

public function getItemByUpc($upc_code, $product_type)
{
$parameters = array("Operation" => "ItemLookup",
"ItemId" => $upc_code,
"SearchIndex" => $product_type,
"IdType" => "UPC",
"ResponseGroup" => "Medium");

$xml_response = $this->queryAmazon($parameters);

return $this->verifyXmlResponse($xml_response);

}

public function getItemByAsin($asin_code)
{
$parameters = array("Operation" => "ItemLookup",
"ItemId" => $asin_code,
"ResponseGroup" => "Medium");

$xml_response = $this->queryAmazon($parameters);

return $this->verifyXmlResponse($xml_response);
}

public function getItemByKeyword($keyword, $product_type)
{
$parameters = array("Operation" => "ItemSearch",
"Keywords" => $keyword,
"SearchIndex" => $product_type);

$xml_response = $this->queryAmazon($parameters);

return $this->verifyXmlResponse($xml_response);
}

}

?>


Raymond

Roundabout Books
Post #1644
Posted 12/14/2013 1:58:54 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Administrators
Last Login: 1/8/2018 7:06:20 PM
Posts: 37, Visits: 220
I am not a php programmer although I can usually figure out what its trying to do.

1st) php was not enabled by default on your account. I turned it on.

2nd) require_once 'aws_signed_request.php'; This file also has to be present.

Andy
Post #1645
Posted 12/21/2013 1:59:42 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: WOB User
Last Login: 3/14/2016 2:22:07 PM
Posts: 47, Visits: 120
Hi Andy,

Thanks so much for the observations--that's very helpful.

Ray


Raymond

Roundabout Books
Post #1646
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 1 (1 guest, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: AndyLL, WOTAdmin

Permissions Expand / Collapse

All times are GMT -6:00, Time now is 9:15pm

Powered By InstantForum.NET v4.1.4 © 2018
Execution: 0.047. 9 queries. Compression Disabled.