如何使用YQL获得更多10个查询结果?

Par*_*ang 6 php yql amazon-web-services amazon-product-api

我试图在PHP中使用YQL,使用amazon.prodlist表和亚马逊产品广告API 从亚马逊获取产品信息.

我使用的查询:

select * from amazon.prodlist where Title='harry potter' and SearchIndex='Books' and ResponseGroup='Images,ItemAttributes'
Run Code Online (Sandbox Code Playgroud)

它只返回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);

?>
Run Code Online (Sandbox Code Playgroud)

这会在页面上显示10个结果.然而,当我在亚马逊网站的"书籍"中搜索"哈利波特"时,我获得了超过3k的结果.有没有办法在一个页面上获得所有结果?请指教.

sal*_*the 3

开放amazon.ecs数据表(在编写问题时)不支持结果分页,因此您只能检索 10 个项目。这是开放数据表作者的常见疏忽。

我已经在自己的 YQL 表存储库分支中修改了数据表源,并发出了拉取请求(此处),希望将更改返回到主要源中。然后,您将能够使用table.name([offset,]count)语法(文档)来获得更多(或更少!)的结果。

如果您想立即启动并运行,那么您需要更改数据表的 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';
Run Code Online (Sandbox Code Playgroud)

当(如果...密切关注拉取请求)更改被拉回主 YQL 表存储库时,您将能够返回使用 http://www.datatables.org/amazon/amazon 。 ecs.xml URL。