1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PEAR の Services_AmazonECS4-0.9.0 を 2011.10.26 の仕様変更以降のProduct Advertising APIに対応させる

Last updated at Posted at 2013-10-11

PEAR の Services_AmazonECS4-0.9.0 を 2011.10.26 の仕様変更以降の Product Advertising API に対応させる方法のメモ

PEAR の Services_Amazon パッケージの v0.9.0 が現状の Product Advertising API に対応していないようだったので、その修正内容のメモ。
API側で廃止されたOperationに対応するメソッド(SellerLookup等)はもちろん使用できないが、
それ以外のOperationの認証と検索はできるようになる。

AmazonECS4.php:85行目を修正

AmazonECS4.php
// define('SERVICES_AMAZON_BASEURL', 'http://webservices.amazon.com/onca/xml?Service=AWSECommerceService');
define('SERVICES_AMAZON_BASEURL', 'http://webservices.amazon.com/onca/xml');

AmazonECS4.php:133行目下あたりにメンバ変数を追加

AmazonECS4.php
    var $_service = 'AWSECommerceService';

AmazonECS4.php:313~318行目を修正

AmazonECS4.php
            /*
            'US' => 'http://webservices.amazon.com/onca/xml?Service=AWSECommerceService',
            'UK' => 'http://webservices.amazon.co.uk/onca/xml?Service=AWSECommerceService',
            'DE' => 'http://webservices.amazon.de/onca/xml?Service=AWSECommerceService',
            'JP' => 'http://webservices.amazon.co.jp/onca/xml?Service=AWSECommerceService',
            'FR' => 'http://webservices.amazon.fr/onca/xml?Service=AWSECommerceService',
            'CA' => 'http://webservices.amazon.ca/onca/xml?Service=AWSECommerceService',
            */
            'US' => 'http://webservices.amazon.com/onca/xml',
            'UK' => 'http://webservices.amazon.co.uk/onca/xml',
            'DE' => 'http://webservices.amazon.de/onca/xml',
            'JP' => 'http://webservices.amazon.co.jp/onca/xml',
            'FR' => 'http://webservices.amazon.fr/onca/xml',
            'CA' => 'http://webservices.amazon.ca/onca/xml',

AmazonECS4.php:1046~1056行目の_buildUrlメソッドを次のように修正

AmazonECS4.php
	function _buildUrl($params)
	{
		$params['AWSAccessKeyId'] = $this->_keyid;
		$params['AssociateTag'] = $this->_associd;
		$params['Service'] = $this->_service;
		$params['Version'] = $this->_version;
		$params['Timestamp'] = gmdate('Y-m-d\TH:i:s\Z');
		ksort($params);
		$canonical_string = '';
		foreach ($params as $k => $v) {
		    $canonical_string .= '&'.str_replace('%7E', '~', rawurlencode($k)).'='.str_replace('%7E', '~', rawurlencode($v));
		}
		$canonical_string = substr($canonical_string, 1);
		$parsed_url = parse_url($this->_baseurl);
		$string_to_sign = "GET\n{$parsed_url['host']}\n{$parsed_url['path']}\n{$canonical_string}";
		$signature = base64_encode(hash_hmac('sha256', $string_to_sign, SECRET_KEY, true));
		$url = $this->_baseurl.'?'.$canonical_string.'&Signature='.str_replace('%7E', '~', rawurlencode($signature));
		return $url;
	}

以上

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?