我正在嘗試在php中使用YQL以使用amazon.prodlist表和亞馬遜產品廣告API從亞馬遜獲取產品信息。如何使用YQL獲得更多的10個結果?
,我使用的查詢:
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);
?>
這將顯示在頁面上10個結果。然而,當我在亞馬遜網站的「圖書」中搜索「哈利波特」時,我獲得了超過3k的結果。有什麼方法可以在一頁上獲得所有結果嗎?請指教。
閱讀[文檔](http://developer.yahoo.com/yql/guide/paging.html)或許? – Wrikken 2011-06-07 18:35:58
我已經閱讀並嘗試將查詢改爲: 'select * from amazon.prodlist(20)其中Title ='$ title'和SearchIndex ='$ sindex'和ResponseGroup ='$ rgroup'', 'select * from amazon.prodlist(0)其中Title ='$ title'和SearchIndex ='$ sindex'和ResponseGroup ='$ rgroup'', 'select * from amazon.prodlist(0)其中Title ='$ title'和SearchIndex ='$ sindex'和ResponseGroup ='$ rgroup'limit 20' 但是我仍然只得到10個結果。還有其他建議嗎? – 2011-06-07 18:51:50
好吧,亞馬遜和YQL都沒有那麼多的經驗,所以我會把它留給其他人,下次你可能會提到那個小事實,但是,節省人們的時間:) – Wrikken 2011-06-07 18:53:57