How to get more than 10 results for a query using YQL?

I am trying to use YQL in php to get product information from Amazon using 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 make it display more than 10 results on one page? Also, no pagination.

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 per page. Whereas when I search for β€œHarry Potter” in the β€œBooks” on the Amazon website, I get over 3,000 results. Is there a way to get all the results on one page? Please inform.

+6
source share
1 answer

The open amazon.ecs data amazon.ecs (at the time of writing your question) does not support paging, so you are stuck only when you extract 10 items. This is a general oversight by the author of an open data table.

I changed the source of the data table in my own YQL table repository fork and issued a transfer request ( here ) in order to hope to get the changes returned to the main sources. You can then use the syntax table.name([offset,]count) ( docs ) to get more (or less!) Results.

If you want to get up immediately and get started, you need to change the URL in the data table to indicate my changes in a special branch for this question only:

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

Your complete query will look something like this (very similar to your existing query):

 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'; 

When (if ... keep an eye on pulling the query ), the changes are returned to the main repository of YQL tables, you will be able to return to using http://www.datatables.org/amazon/amazon.ecs.xml .

+3
source

Source: https://habr.com/ru/post/889982/


All Articles