6

php でYQLを使用して、 amazon.prodlistテーブルと Amazon Product Advertising APIを使用して Amazon から製品情報を取得しようとしています。

私が使用したクエリ:

select * from amazon.prodlist where Title='harry potter' and SearchIndex='Books' and ResponseGroup='Images,ItemAttributes'

10 件の結果のみが返されます。同じページに 10 件を超える結果を表示するにはどうすればよいですか? また、ページネーションなし。

完全な PHP コード:

<?php
$BASE_URL = "https://query.yahooapis.com/v1/public/yql";

$key="my_key";
$secret="my_secret";
$title="harry potter";
$sindex="Books";
$rgroup="Images,ItemAttributes";
$events="";
     

// Form YQL query and build URI to YQL Web service
$yql_query = "use 'http://www.datatables.org/amazon/amazon.ecs.xml' as amazon.prodlist;
set AWSAccessKeyId='$key' on amazon.prodlist;
set secret='$secret' on amazon.prodlist; 
select * from amazon.prodlist where Title='$title' and SearchIndex='$sindex' and ResponseGroup='$rgroup' ";

$yql_query_url = $BASE_URL . "?q=" . urlencode($yql_query) . "&format=json";

// Make call with cURL
$session = curl_init($yql_query_url);
curl_setopt($session, CURLOPT_RETURNTRANSFER,true);
$json = curl_exec($session);
// Convert JSON to PHP object 
$phpObj =  json_decode($json);

// Confirm that results were returned before parsing
if(!is_null($phpObj->query->results)){
  // Parse results and extract data to display
  foreach($phpObj->query->results->Item as $event){
    $events .= "<div><h2>" . $event->ItemAttributes->Title . " by " . $event->ItemAttributes->Author . "</h2></div>";
}
}
// No results were returned
if(empty($events)){
  $events = "Sorry, no events matching result";
}
// Display results and unset the global array $_GET
echo $events;
unset($_GET);

?>

これにより、1 ページに 10 件の結果が表示されます。一方、Amazon Web サイトの「本」で「ハリー・ポッター」を検索すると、3,000 件以上の結果が得られます。1 つのページ自体ですべての結果を取得する方法はありますか? お知らせ下さい。

4

1 に答える 1

3

オープン データ テーブル(amazon.ecs質問を書いている時点) は結果のページングをサポートしていないため、10 項目しか取得できません。これは、オープン データ テーブルの作成者のよくある見落としです。

YQL テーブル リポジトリの独自のフォークでデータ テーブル ソースを修正し、プル リクエスト (こちら) を発行して、変更をメイン ソースに戻すことを願っています。その後、table.name([offset,]count)構文 ( docs ) を使用して、より多くの (またはより少ない!) 結果を取得できます。

すぐに起動して実行したい場合は、URL をデータ テーブルに変更して、この質問のためだけに特別なブランチで私の変更を指すようにする必要があります。

https://github.com/salathe/yql-tables/blob/so-6269923/amazon/amazon.ecs.xml

完全なクエリは次のようになります (既存のクエリと非常によく似ています)。

use 'https://raw.github.com/salathe/yql-tables/so-6269923/amazon/amazon.ecs.xml' as amazon.prodlist;
use AWSAccessKeyId='my_access_key' on amazon.prodlist;
use secret='my_secret' on amazon.prodlist; 

select *
from amazon.prodlist(50) 
where Title='harry potter' 
  and SearchIndex='Books' 
  and ResponseGroup='Images,ItemAttributes';

(プル リクエストに注意してください) 変更がメインの YQL テーブル リポジトリに戻されると、http://www.datatables.org/amazon/amazon の使用に戻ることができます。 ecs.xml URL。

于 2011-06-07T21:29:55.647 に答える