<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>code-diesel &#187; api</title>
	<atom:link href="http://www.codediesel.com/tag/api/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codediesel.com</link>
	<description>/* PHP &#38; MySQL Journal */</description>
	<lastBuildDate>Thu, 02 Feb 2012 13:19:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Accessing Amazon Product Advertising API</title>
		<link>http://www.codediesel.com/php/accessing-amazon-product-advertising-api-in-php/</link>
		<comments>http://www.codediesel.com/php/accessing-amazon-product-advertising-api-in-php/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 05:39:49 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[libraries]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[api]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=1457</guid>
		<description><![CDATA[amazon product advertising api tutorial]]></description>
			<content:encoded><![CDATA[<p><strong>Updated: 19th October 2011</strong></p>
<p>In this post we will see how to access the Amazon Product Advertising API from PHP. Amazon has recently changed (from 15th Aug &#8217;09) the authentication mechanism for accessing their API which must now be signed with your Amazon keys. Unsigned requests will be rejected by Amazon. Also now Amazon Associate Tag is required in the query (effective from 25th Oct. 2011). Note that the code uses the hash_hmac() hash function which is only available for PHP versions 5.1.2 and above, so the code will not work for versions below that.<br />
<span id="more-1457"></span></p>
<h4>A small example</h4>
<p>Below is an example to access the Amazon Product Advertising API using the provided class.</p>

<div class="wp_codebox"><table><tr id="p14571"><td class="code" id="p1457code1"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/* Example usage of the Amazon Product Advertising API */</span>
    <span style="color: #000000; font-weight: bold;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;amazon_api_class.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$obj</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AmazonProductAPI<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    try
    <span style="color: #009900;">&#123;</span>
        <span style="color: #009933; font-style: italic;">/* Returns a SimpleXML object */</span>
         <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$obj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">searchProducts</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;X-Men Origins&quot;</span><span style="color: #339933;">,</span>
                                       AmazonProductAPI<span style="color: #339933;">::</span><span style="color: #004000;">DVD</span><span style="color: #339933;">,</span>
                                       <span style="color: #0000ff;">&quot;TITLE&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    catch<span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h4>The API access class</h4>
<p>Given below is the implementation of the class to access the Amazon Product Advertising API. Comments have been removed for brevity, but are included in the source download. Note that only a few access operations are implemented in the class: <em>ItemLookup</em>, <em>ItemSearch</em>; there are more available in the API, a complete list can be found <a target="_blank" href="http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/CHAP_OperationListAlphabetical.html">here</a>. It&#8217;s just a simple matter of changing some parameters to implement others.</p>

<div class="wp_codebox"><table><tr id="p14572"><td class="code" id="p1457code2"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">require_once</span> <span style="color: #0000ff;">'aws_signed_request.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> AmazonProductAPI
<span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$public_key</span>     <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;YOUR AMAZON ACCESS KEY ID&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$private_key</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;YOUR AMAZON SECRET KEY&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/* 'Associate Tag' now required, effective from 25th Oct. 2011 */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$associate_tag</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;YOUR AMAZON ASSOCIATE TAG&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">const</span> MUSIC <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Music&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">const</span> DVD   <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;DVD&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">const</span> GAMES <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;VideoGames&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> verifyXmlResponse<span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">False</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Could not connect to Amazon&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Items</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ItemAttributes</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Title</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">else</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Invalid xml response.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> queryAmazon<span style="color: #009900;">&#40;</span><span style="color: #000088;">$parameters</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> aws_signed_request<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;com&quot;</span><span style="color: #339933;">,</span>
                                  <span style="color: #000088;">$parameters</span><span style="color: #339933;">,</span>
                                  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">public_key</span><span style="color: #339933;">,</span>
                                  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">private_key</span><span style="color: #339933;">,</span>
                                  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">associate_tag</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> searchProducts<span style="color: #009900;">&#40;</span><span style="color: #000088;">$search</span><span style="color: #339933;">,</span><span style="color: #000088;">$category</span><span style="color: #339933;">,</span><span style="color: #000088;">$searchType</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UPC&quot;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$allowedTypes</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPC&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;TITLE&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;ARTIST&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;KEYWORD&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$allowedCategories</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Music&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;DVD&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;VideoGames&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$searchType</span><span style="color: #009900;">&#41;</span> 
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #0000ff;">&quot;UPC&quot;</span> <span style="color: #339933;">:</span>
                <span style="color: #000088;">$parameters</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Operation&quot;</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;ItemLookup&quot;</span><span style="color: #339933;">,</span>
                                    <span style="color: #0000ff;">&quot;ItemId&quot;</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$search</span><span style="color: #339933;">,</span>
                                    <span style="color: #0000ff;">&quot;SearchIndex&quot;</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$category</span><span style="color: #339933;">,</span>
                                    <span style="color: #0000ff;">&quot;IdType&quot;</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;UPC&quot;</span><span style="color: #339933;">,</span>
                                    <span style="color: #0000ff;">&quot;ResponseGroup&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Medium&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                            <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #0000ff;">&quot;TITLE&quot;</span> <span style="color: #339933;">:</span>
                <span style="color: #000088;">$parameters</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Operation&quot;</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;ItemSearch&quot;</span><span style="color: #339933;">,</span>
                                    <span style="color: #0000ff;">&quot;Title&quot;</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$search</span><span style="color: #339933;">,</span>
                                    <span style="color: #0000ff;">&quot;SearchIndex&quot;</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$category</span><span style="color: #339933;">,</span>
                                    <span style="color: #0000ff;">&quot;ResponseGroup&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Medium&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                            <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$xml_response</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">queryAmazon</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parameters</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">verifyXmlResponse</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml_response</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getItemByUpc<span style="color: #009900;">&#40;</span><span style="color: #000088;">$upc_code</span><span style="color: #339933;">,</span> <span style="color: #000088;">$product_type</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$parameters</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Operation&quot;</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;ItemLookup&quot;</span><span style="color: #339933;">,</span>
                            <span style="color: #0000ff;">&quot;ItemId&quot;</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$upc_code</span><span style="color: #339933;">,</span>
                            <span style="color: #0000ff;">&quot;SearchIndex&quot;</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$product_type</span><span style="color: #339933;">,</span>
                            <span style="color: #0000ff;">&quot;IdType&quot;</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;UPC&quot;</span><span style="color: #339933;">,</span>
                            <span style="color: #0000ff;">&quot;ResponseGroup&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Medium&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$xml_response</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">queryAmazon</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parameters</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">verifyXmlResponse</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml_response</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getItemByAsin<span style="color: #009900;">&#40;</span><span style="color: #000088;">$asin_code</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$parameters</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Operation&quot;</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;ItemLookup&quot;</span><span style="color: #339933;">,</span>
                            <span style="color: #0000ff;">&quot;ItemId&quot;</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$asin_code</span><span style="color: #339933;">,</span>
                            <span style="color: #0000ff;">&quot;ResponseGroup&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Medium&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$xml_response</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">queryAmazon</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parameters</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">verifyXmlResponse</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml_response</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getItemByKeyword<span style="color: #009900;">&#40;</span><span style="color: #000088;">$keyword</span><span style="color: #339933;">,</span> <span style="color: #000088;">$product_type</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$parameters</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Operation&quot;</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;ItemSearch&quot;</span><span style="color: #339933;">,</span>
                            <span style="color: #0000ff;">&quot;Keywords&quot;</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$keyword</span><span style="color: #339933;">,</span>
                            <span style="color: #0000ff;">&quot;SearchIndex&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$product_type</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$xml_response</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">queryAmazon</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parameters</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">verifyXmlResponse</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml_response</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h4>Amazon signed request</h4>
<p>The above class uses the &#8216;aws_signed_request&#8217; function to generate the new request signature. Original code is by <a target="_blank" href="http://mierendo.com/">Ulrich Mierendorff</a>, modified here to use cURL.</p>

<div class="wp_codebox"><table><tr id="p14573"><td class="code" id="p1457code3"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span>  aws_signed_request<span style="color: #009900;">&#40;</span><span style="color: #000088;">$region</span><span style="color: #339933;">,</span>
                             <span style="color: #000088;">$params</span><span style="color: #339933;">,</span>
                             <span style="color: #000088;">$public_key</span><span style="color: #339933;">,</span>
                             <span style="color: #000088;">$private_key</span><span style="color: #339933;">,</span>
                             <span style="color: #000088;">$associate_tag</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000088;">$method</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;GET&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$host</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ecs.amazonaws.&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$region</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$uri</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/onca/xml&quot;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;Service&quot;</span><span style="color: #009900;">&#93;</span>          <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;AWSECommerceService&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;AWSAccessKeyId&quot;</span><span style="color: #009900;">&#93;</span>   <span style="color: #339933;">=</span> <span style="color: #000088;">$public_key</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;AssociateTag&quot;</span><span style="color: #009900;">&#93;</span>     <span style="color: #339933;">=</span> <span style="color: #000088;">$associate_tag</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;Timestamp&quot;</span><span style="color: #009900;">&#93;</span>        <span style="color: #339933;">=</span> <span style="color: #990000;">gmdate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y-m-d<span style="color: #000099; font-weight: bold;">\T</span>H:i:s\Z&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;Version&quot;</span><span style="color: #009900;">&#93;</span>          <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;2009-03-31&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/* The params need to be sorted by the key, as Amazon does this at
      their end and then generates the hash of the same. If the params
      are not in order then the generated hash will be different from
      Amazon thus failing the authentication process.
    */</span>
    <span style="color: #990000;">ksort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$canonicalized_query</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span> <span style="color: #000000; font-weight: bold;">as</span> <span style="color: #000088;">$param</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$param</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;%7E&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;~&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">rawurlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;%7E&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;~&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">rawurlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$canonicalized_query</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$param</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000088;">$canonicalized_query</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$canonicalized_query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$string_to_sign</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$method</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$host</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$uri</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">.</span>
                            <span style="color: #000088;">$canonicalized_query</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/* calculate the signature using HMAC, SHA256 and base64-encoding */</span>
    <span style="color: #000088;">$signature</span> <span style="color: #339933;">=</span> <span style="color: #990000;">base64_encode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">hash_hmac</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sha256&quot;</span><span style="color: #339933;">,</span> 
                                  <span style="color: #000088;">$string_to_sign</span><span style="color: #339933;">,</span> <span style="color: #000088;">$private_key</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">True</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/* encode the signature for the request */</span>
    <span style="color: #000088;">$signature</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;%7E&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;~&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">rawurlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$signature</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/* create request */</span>
    <span style="color: #000088;">$request</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$host</span><span style="color: #339933;">.</span><span style="color: #000088;">$uri</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;?&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$canonicalized_query</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;Signature=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$signature</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/* I prefer using CURL */</span>
    <span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span><span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_TIMEOUT<span style="color: #339933;">,</span> <span style="color: #cc66cc;">15</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_SSL_VERIFYHOST<span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$xml_response</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml_response</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">False</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900; font-weight: bold;">False</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #009933; font-style: italic;">/* parse XML and return a SimpleXML object, if you would
           rather like raw xml then just return the $xml_response.
         */</span>
        <span style="color: #000088;">$parsed_xml</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">simplexml_load_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml_response</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$parsed_xml</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">False</span><span style="color: #009900;">&#41;</span> ? <span style="color: #009900; font-weight: bold;">False</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$parsed_xml</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<div  class="download2">
<a href="http://www.codediesel.com/downloads/amazonapi">Download Source</a><br />
<span>Downloads : 4890  / File size : 5 kB</span>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/php/accessing-amazon-product-advertising-api-in-php/feed/</wfw:commentRss>
		<slash:comments>63</slash:comments>
		</item>
		<item>
		<title>NewYork Times Bestseller API access in PHP</title>
		<link>http://www.codediesel.com/php/newyork-times-bestseller-api-access-in-php/</link>
		<comments>http://www.codediesel.com/php/newyork-times-bestseller-api-access-in-php/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 15:20:12 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[api]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=306</guid>
		<description><![CDATA[The New York Times has started offering a set of APIs for their various data services. On January 27th they released the API for their Best-Seller list. According to NYTimes : Like many organizations, we hope to encourage innovation through collaboration. When you build applications, create mashups and otherwise reveal the potential of our data, [...]]]></description>
			<content:encoded><![CDATA[<p>The New York Times has started offering a set of <a target="_blank" href="http://developer.nytimes.com/docs?authChecked=1">APIs</a> for their various data services. On January 27th they released the API for their Best-Seller list. According to NYTimes :</p>
<p><em>Like many organizations, we hope to encourage innovation through collaboration. When you build applications, create mashups and otherwise reveal the potential of our data, we learn more about what our readers want and gain insight into how news and information can be reimagined. We&#8217;re hoping you&#8217;ll show us what&#8217;s next for The Times.</em><br />
<span id="more-306"></span></p>
<p>Currently the list offers every weekly list since June 2008 which will eventually go back to the 1930s. According to their blog, the API offers details about specific best sellers, including historical rank information and links to New York Times reviews and excerpts. I created a short class to access the api using CURL. To access the api you need to sign up for an API key <a title="nytimes api key" href="http://developer.nytimes.com/apps/register" target="_blank">here</a>. The api returns data in xml, json or sphp (serialized php).</p>
<p>A sample code using the class is shown below:</p>

<div class="wp_codebox"><table><tr id="p3068"><td class="code" id="p306code8"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$books</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> nyTimesBooks<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;your api key here&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$books</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$books</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;xml&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009933; font-style: italic;">// Set return format to xml</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">listDate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;2008-10-01&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009933; font-style: italic;">// publication date (YYYY-MM-DD)</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">listType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Series-Books&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009933; font-style: italic;">// List type</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #000088;">$books</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_bestsellers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The list type can be any of the following:</p>
<p>* Hardcover-Fiction<br />
* Hardcover-Nonfiction<br />
* Hardcover-Advice<br />
* Paperback-Nonfiction<br />
* Paperback-Advice<br />
* Trade-Fiction-Paperback<br />
* Picture-Books<br />
* Chapter-Books<br />
* Paperback-Books<br />
* Series-Books<br />
* Mass-Market-Paperback</p>
<p>Or you can get the list as follows:</p>

<div class="wp_codebox"><table><tr id="p3069"><td class="code" id="p306code9"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$books</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> nyTimesBooks<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;your api key here&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #000088;">$books</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_list_names</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>You can also use the class without any options which will return the current list in xml format with the list type of &#8216;Mass-Market-Paperback&#8217;.</p>

<div class="wp_codebox"><table><tr id="p30610"><td class="code" id="p306code10"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$books</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> nyTimesBooks<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;your api key here&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #000088;">$books</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_bestsellers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>A sample xml output is shown below:</p>

<div class="wp_codebox"><table><tr id="p30611"><td class="code" id="p306code11"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;result_set<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;status<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>OK<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/status<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;copyright<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Copyright (c) 2009 The New York Times Company.  All Rights Reserved.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/copyright<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;num_results<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>20<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/num_results<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;results<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rank<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rank<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;list_name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Paperback Nonfiction<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/list_name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bestsellers_date<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2008-09-21<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bestsellers_date<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;published_date<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2008-10-05<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/published_date<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;weeks_on_list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>86<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/weeks_on_list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rank_last_week<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rank_last_week<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;asterisk<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/asterisk<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dagger<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dagger<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;book_details<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;book_detail<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>THREE CUPS OF TEA<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>A former climber builds schools in villages in Pakistan and Afghanistan.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;contributor<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>by Greg Mortenson and David Oliver Relin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/contributor<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Greg Mortenson and David Oliver Relin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;contributor_note</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>15<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;age_group</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;publisher<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Penguin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/publisher<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/book_detail<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/book_details<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;isbns<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;isbn<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;isbn13<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>9780143038252<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/isbn13<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;isbn10<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0143038257<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/isbn10<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/isbn<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;isbn<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;isbn13<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>9780670034826<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/isbn13<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;isbn10<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0670034827<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/isbn10<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/isbn<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;isbn<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;isbn13<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>9781597226240<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/isbn13<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;isbn10<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>159
.
.
.</pre></td></tr></table></div>

<p>The code still needs to implement the following requests:<br />
1. search best-seller lists<br />
2. history of a best seller </p>
<div class="download"><a href="/data/code/nytimes.zip">Download code</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/php/newyork-times-bestseller-api-access-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

