php - Paginating over travel destinations in Freebase -


i trying fetch travel destinations freebase api. according documentation using cursor , limit parameters. start cursor @ 0 , limit 100, add 100 cursor in every iteration. problem getting 76 results way. there should cca 1500 travel destinations in freebase database.

documentation:

https://developers.google.com/freebase/v1/search

here code:

<?php  require_once __dir__ . '/vendor/autoload.php';  $apikey = 'super_secret_api_key';  use guzzle\http\client;  //// google freebase $client = new client('https://www.googleapis.com');  $cursor = 0; $limit = 100; $results = array();  {      $request = $client->get('/freebase/v1/search');     $request->getquery()->set('key', $apikey);     $request->getquery()->set('filter', '(all type:/travel/travel_destination)');     $request->getquery()->set('cursor', $cursor);     $request->getquery()->set('limit', $limit);     $request->getquery()->set('indent', 'true');     $request->getquery()->set('query', '');      $response = $request->send()->json();      foreach ($response['result'] $result) {         $results[] = $result;     }      $cursor += $limit;  } while (count($response['result']) > 0);  echo count($results);exit; 

it prints 76.

returning exhaustive results isn't intended use case search api, better done using either mql or bulk data dumps.

since first query returns full 100 results, i'm assuming there's bug in php. if had guess, i'd guess you're either counting number of iterations or number of results returned in last iteration, latter.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -