2009-10-18 5 views
3

아마존에서 항목 목록을 출력하는 다음 코드가 있지만 특정 제품 (예 : 리뷰, 리뷰 등)에 액세스하는 방법을 모르겠습니다. 어떤 도움을 주시면 감사하겠습니다.Amazon API를 사용하여 제품 세부 정보 얻기

<?php 



    function makeAWSUrl($parameters, $associate_tag, $access_key, $secret_key, $aws_version = '2009-06-01') { 



     $host = 'ecs.amazonaws.com'; 

     $path = '/onca/xml'; 



     $query = array(  

     'Service' => 'AWSECommerceService', 

     'AWSAccessKeyId' => $access_key, 

     'AssociateTag' => $associate_tag, 

     'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'), 

     'Version' => $aws_version, 

     ); 



     // Merge in any options that were passed in 

     if (is_array($parameters)) { 

      $query = array_merge($query, $parameters); 

     } 



     // Do a case-insensitive, natural order sort on the array keys. 

     ksort($query); 



     // create the signable string 

     $temp = array(); 



     foreach ($query as $k => $v) { 

      $temp[] = str_replace('%7E', '~', rawurlencode($k)) . '=' . str_replace('%7E', '~', rawurlencode($v)); 

     } 



     $signable = implode('&', $temp); 



     $stringToSign = "GET\n$host\n$path\n$signable"; 



     // Hash the AWS secret key and generate a signature for the request. 



     $hex_str = hash_hmac('sha256', $stringToSign, $secret_key); 



     $raw = ''; 



     for ($i = 0; $i < strlen($hex_str); $i += 2) { 

      $raw .= chr(hexdec(substr($hex_str, $i, 2))); 

     } 



     $query['Signature'] = base64_encode($raw); 

     ksort($query); 



     $temp = array(); 



     foreach ($query as $k => $v) { 

      $temp[] = rawurlencode($k) . '=' . rawurlencode($v); 

     } 



     $final = implode('&', $temp); 



     return 'http://' . $host . $path . '?' . $final; 

    } 



    $url = makeAWSUrl(array('Keywords' => 'ipod',       

    'Operation' => 'ItemSearch',       

    'SearchIndex' => 'Electronics'), 

    'ResponseGroup' => 'Medium',       

    'someid', 'aaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaaaaaaaaaaaaa'); 





    $response = simplexml_load_file($url); 



    foreach ($response->Items->Item as $item) 

    { 

     $Title [] = $item->ItemAttributes->Title; 

    } 





    foreach($Title as $CurrentTitle) 

    { 

     echo "<h2>".$CurrentTitle."</h2>"; 

    } 







?> 

답변

6

$response->Items->Item 목록에는 검색어와 일치하는 모든 항목/기사가 포함되어 있습니다. 이 목록의 입니다. 이 객체들 각각은 성질을 가질 수있는 ItemAtributes과 같은 속성을 가지고 있습니다.

어떤 속성을 사용할 수 있는지 확인하려면 documentation을보십시오. 예를 들어 ItemAttributes->ListPrice->Amount에는 해당 품목의 가격이 포함되어 있습니다.

그래서 각 결과에 대한 출력 가격과 제목, 예를 들어

$response = simplexml_load_file($url); 
foreach ($response->Items->Item as $item) { 
    echo "<h2>".$item->ItemAttributes->Title."</h2>"; 
    echo "Price: ".$item->ItemAttributes->ListPrice->Amount; 
} 
+0

덕분에 코드를 변경할 수 있지만, 나는 분명 생각하지 않습니다. 위의 코드와 같은 키워드에 대해 많은 결과를 얻는 대신 특정 제품에 대한 데이터를 얻을 수 있습니까? 나는 이미 asin을 알고 있다고 가정합시다. – user149109

+0

우수, 빠른 응답을 가져 주셔서 감사합니다. – user149109

관련 문제