[英]How to get more that 10 results for a query using YQL?
我正在嘗試在 php 中使用YQL ,使用amazon.prodlist表和亞馬遜產品廣告 API 從亞馬遜獲取產品信息。
我使用的查詢:
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 條結果。 有沒有辦法在一個頁面上獲得所有結果? 請指教。
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 表存儲庫時,您將能夠 go 重新使用http://www.datatables.org/amazon/amazon。 ecs.xml URL。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.