Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Last active January 25, 2016 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurozumi/c579b5c407bcb39a3acb to your computer and use it in GitHub Desktop.
Save kurozumi/c579b5c407bcb39a3acb to your computer and use it in GitHub Desktop.
【Amazon Product Adverstising API】ASINからパッケージ寸法を取得できるクラスの使い方
<?php
require_once "vendor/autoload.php";
use ApaiIO\Configuration\GenericConfiguration;
use ApaiIO\ResponseTransformer\XmlToSimpleXmlObject;
use ApaiIO\Operations\Lookup;
use ApaiIO\ApaiIO;
use Acme\ItemLookup;
$conf = new GenericConfiguration();
$conf
->setCountry('com')
->setAccessKey(AWS_API_KEY)
->setSecretKey(AWS_API_SECRET_KEY)
->setAssociateTag(AWS_ASSOCIATE_TAG);
$apaiIO = new ApaiIO($conf);
$search = new Lookup();
$search->setCategory('DVD');
$search->setActor('Bruce Willis');
$search->setKeywords('Die Hard');
$response = $apaiIO->runOperation($search);
$itemLookup = new ItemLookup(simplexml_load_string($response));
if ($itemLookup->isValid()) {
foreach ($itemLookup as $item)
{
$data[] = [
"asin" => $itemLookup->getAsin(),
"weight" => $itemLookup->getWeight(),
"width" => $itemLookup->getWidth(),
"height" => $itemLookup->getHeight(),
"length" => $itemLookup->getLength(),
"title" => $itemLookup->getTitle(),
"salesrank" => $itemLookup->getSalesRank()
];
}
if($itemLookup->getError()){
foreach($itemLookup->getError()->Error as $error)
echo $error;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment