如何使用 YQL 获取超过 10 个查询结果?
我正在尝试在 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 个结果。然而,当我在亚马逊网站的“图书”中搜索“哈利·波特”时,我得到了超过 3000 个结果。有什么办法可以在一页上获得所有结果吗?请指教。
I am trying to use YQL in php to get product information from Amazon using the amazon.prodlist table and Amazon Product Advertising API.
The query that I used:
select * from amazon.prodlist where Title='harry potter' and SearchIndex='Books' and ResponseGroup='Images,ItemAttributes'
It returns only 10 results. How can I get it to display more that 10 results on the same page? Also, without pagination.
The full PHP code:
<?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);
?>
This displays 10 results on a page. Whereas, when I search for 'harry potter' in 'Books' on Amazon website, I get more than 3k results. Is there any way to get all the results on one page itself? Please advise.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
amazon.ecs
开放数据表(在编写问题时)不支持结果分页,因此您只能检索 10 个项目。这是开放数据表作者的常见疏忽。我已经在自己的 YQL 表存储库分支中修改了数据表源,并发出了拉取请求 (此处)希望将更改重新纳入主要来源。然后,您将能够使用
table.name([offset,]count)
语法 (docs)以获得更多(或更少!)结果。如果您想立即启动并运行,那么您需要更改数据表的 URL,以指向我在一个特殊分支中针对此问题所做的更改:
您的完整查询将如下所示(非常与您现有的查询):
何时(如果...密切关注 拉取请求)更改将被拉回到主 YQL 表存储库中,您将能够返回使用 http://www.datatables.org/amazon/amazon.ecs.xml 网址。
The
amazon.ecs
open data table (at the time of writing your question) does not support paging of results, so you are stuck with only retrieving the 10 items. This is a common oversight on the part of the open data table author.I have amended the data table source in my own fork of the YQL tables repository, and issued a pull request (here) to hopefully get the changes back into the main sources. You will then be able to use the
table.name([offset,]count)
syntax (docs) to get more (or fewer!) results.If you want to get up and running right away, then you need to change the URL to the data table to point at my changes in a special branch just for this question:
Your full query would look something like the following (very similar to your existing query):
When (if... keep an eye on the pull request) the changes are pulled back into the main YQL tables repository, you will be able to go back to using the http://www.datatables.org/amazon/amazon.ecs.xml URL.