'AWSECommerceService', 'AWSAccessKeyId' => $awsAccessKeyID, 'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'), # 'IdType' => 'ISBN', # 'ItemId' => $isbn, # 'Operation' => 'ItemLookup', 'ResponseGroup' => 'ItemAttributes', 'SearchIndex' => 'Books', 'Operation' => 'ItemSearch', 'SearchIndex' => 'Books', 'Keywords' => urlencode($keywords), ); ksort($args); $parts = array(); foreach(array_keys($args) as $key) { $parts[] = $key . "=" . $args[$key]; } // Construct the string to sign $stringToSign = "GET\n" . $host . "\n" . $path . "\n" . implode("&", $parts); $stringToSign = str_replace('+', '%20', $stringToSign); $stringToSign = str_replace(':', '%3A', $stringToSign); $stringToSign = str_replace(';', urlencode(';'), $stringToSign); // Sign the request $signature = hash_hmac("sha256", $stringToSign, $awsSecretKey, TRUE); // Base64 encode the signature and make it URL safe $signature = base64_encode($signature); $signature = str_replace('+', '%2B', $signature); $signature = str_replace('=', '%3D', $signature); $signature = str_replace(' ', '%20', $signature); // Construct the URL $url = 'http://' . $host . $path . '?' . implode("&", $parts) . "&Signature=" . $signature; //Catch the response in the $parsed_xml object $parsed_xml = simplexml_load_file($url) or drupal_set_message ("amazon: book search failed",error); //$parsed_xml = simplexml_load_string($response); //printSearchResults($parsed_xml, $SearchIndex); $amazonresults = array(); foreach($parsed_xml->Items->Item as $current){ $year_pattern = "/[0-9]{4}/"; $raw_date = utf8_decode((string)$current->ItemAttributes->PublicationDate); if( preg_match( $year_pattern, $raw_date, $matches ) ) { $publication_year = $matches[0]; } else { $publication_year = $raw_date; } foreach($current->ItemAttributes->Author as $author) { $authors[] = utf8_decode((string)$author); } $author_s = implode(', ', $authors); $amazonresults[] = array( "title" => utf8_decode((string)$current->ItemAttributes->Title), "authors" => $author_s, "publisher" => utf8_decode((string)$current->ItemAttributes->Publisher), "isbn" => utf8_decode((string)$current->ItemAttributes->ISBN), "year" => $publication_year, "date" => $raw_date, "item_link" => utf8_decode((string)$current->DetailPageURL), "query_url" => $url, //"SmallImageURL" => utf8_decode((string)$current->ItemAttributes->SmallImageURL), ); } #print_r($amazonresults); die(); return $amazonresults; }