Indeed API XML feed always returns only 25 results

為{幸葍}努か 提交于 2019-12-12 17:33:10

问题


I'm trying to use the Indeed.com XML Feed API's in a PHP website. I use this script https://github.com/indeedlabs/indeed-php, see how it works on the Github page (very good script, thanks to the author).

It works but Indeed always returns only 25 results for jobs, even when I set the 'limit', 'start' and 'end' parameters.

Here are the parameters I send :

$aParams = array(
         "q" => "php",
         "l" => "paris",
         "co" => "FR",
         "limit" => 10000,
         "sort" => "date",
         "start" => 0,
         "end" => 100,
         "userip" => $_SERVER["REMOTE_ADDR"],
         "useragent" => $_SERVER["HTTP_USER_AGENT"],
             "v" => 2,
             "format" => "json",
             "publisher" => "123456789"
   );

An array is returned and contains :

[version] = 2 
[query] = 'php'
[location] = 'paris'            
[dupefilter] = 'true'
[highlight] = 'true' 
[start] = 1 
[end] = 25  
[totalResults] = 2068  
[pageNumber] = 0 
[results] = an array which contains the jobs informations 

As we can see, totalResults is equal to 2058 but real the jobs results array always contains only 25 entries.

It seems to be a pagination issue (read here : http://forums.appthemes.com/report-jobroller-bugs/indeed-integration-api-37420) but I don't understand the goal : why proceed like this and not more simply ? So I have to do many requests : one to know first the 'totalResults' and save it (in session for example) and other requests to paginate the results 25 by 25 until the last?

Are there any developers who use this API and how do you proceed?

Thanks


回答1:


Right Indeed limits the feed to 25 at a time. I have written script to get round this. In the Indeed $params you can specify a 'start' which as default is 0.

I have created a script which using the job count creates a foreach loop and loops the API changing the 'start' to keep getting different results until theres no more left. Then it puts it all into a single PHP array.

Single API request just so we can get totalResults (count of total jobs)

$client = new Indeed("YOUR_ID");
$args_count = array(
    "q" => "YOUR SEARCH QUERY",
    "l" => "",
    "co" => "GB",
    "userip" => "1.2.3.4",
    "limit" => 10000,
    "useragent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2)"
);

Once we have the total job count we divide it by 25 and round the result up. This is so we know how many times we need to run our foreach

$totalResults = $client->search($args_count);
$totalCount = $totalResults['totalResults'] / 25;
$loop_to_count = ceil($totalCount); 

We create a array starting with 0 and going up in 25s to as many as you require. My below will return 150 results.

$counter = 0;
$loop_options = array('0', '25', '50', '75', '100', '125', '150');

Then we start the main foreach:

$results = '';

foreach ($loop_options as $options) {

    $params = array(
    "q" => "YOUR SEARCH QUERY",
    "l" => "",
    "co" => "GB",
    "userip" => "1.2.3.4",
    "limit" => 10000,
    "start"  => $options,
    "useragent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2)"
    );
    $getResults = $client->search($params);

   foreach ($getResults['results'] as $rawResults) {

       $Subresults[] = array(
        'jobtitle' => $rawResults['jobtitle'],
        'company' => $rawResults['company'],
        'city' => $rawResults['city'],
        'state' => $rawResults['state'],
        'country' => $rawResults['country'],
        'language' => $rawResults['language'],
        'formattedLocation' => $rawResults['formattedLocation'],
        'source' => $rawResults['source'],
        'date' => $rawResults['date'],
        'snippet' => $rawResults['snippet'],
        'url' => $rawResults['url'],
        'onmousedown' => $rawResults['onmousedown'],
        'jobkey' => $rawResults['jobkey'],
        'sponsored' => $rawResults['sponsored'],
        'expired' => $rawResults['expired'],
        'indeedApply' => $rawResults['indeedApply'],
        'formattedLocationFull' => $rawResults['formattedLocationFull'],
        'formattedRelativeTime' => $rawResults['formattedRelativeTime'],
        'stations' => $rawResults['stations']
        );
   }
    $counter++;
    if ($counter == $loop_to_count) { break; }
}

Finally all our results are inside this array:

$results = array ('results' => $Subresults);

$results will contains all the jobs you have posted on Indeed




回答2:


please give limit attribute i gave 50 eg : http://api.indeed.com/ads/apisearch?publisher=1772xxxxxxxxx&q=java&l=austin%2C%20tx&sort=&radius=&st=&jt=&start=&limit=50&fromage=&filter=&latlong=1&co=us&chnl=&userip=1.2.3.4&useragent=Mozilla/%2F4.0%28Firefox%29&v=2

Here you are using a library so you have to modify library function process_request() , in that function add a line $args["limit"] = 50; . here i just gave 50 you can initialize whatever number you want.



来源:https://stackoverflow.com/questions/22098850/indeed-api-xml-feed-always-returns-only-25-results

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!