About Indeed.com

Indeed is a meta search engine over the Internet which gives job seekers free access to millions of employment opportunities from thousands of websites in a single search as job feeds. It includes all the job listings from job boards, newspapers and associations. Here in this blog post, you can know how to load the indeed jobs to your website with simple steps of PHP codes.

Steps to Integrate Indeed API

Step 1: Create an account in indeed.

Step 2: Copy sample XML request.

Step 3: Create a function to send URL request.

Step 4: Create a function to convert XML to Array.

Step 5: Create a page “indeed.php”

Step 6: Create a page index.php to display results.

 

Step 1: Create an account in indeed

To make indeed integration with your website you must create an account at indeed.com . After logging in you can see the API link in the footer of  indeed.com. By clicking on it you will redirect to a indeed publisher page and you can login with your details. There you can select XML Feed option from the menu bar which provides all details about indeed XML Feed.

 

Step 2: Copy sample XML request

After selecting XML Feed you will get a sample XML request including your publisher id like this “http://api.indeed.com/ads/apisearch?publisher=9xxxxxxxxxxxxxx&q=java&l=austin%2C+tx&sort=&radius=&st=

&jt=&start=&limit=&fromage=&filter=&latlong=1&co=us&chnl=&userip=1.2.3.4&useragent=Mozilla/%2F4.0%28Firefox%29&v=2”.

Also you can easily understand that what does each variable in the URL means and how to use it. You can copy this api into your webpage where you need to show the indeed jobs.

 

Step 3:  Create a PHP Code function to send URL request.

We need to create a function to get the XML feed from the indeed. This function helps us to send the URL request. It is with this URL request that we get the XML feed. Also you can add or change variable values in the URL as like your need. Here I changed some variables like query q=php, limit=25. By default it only pulls 10 job details from indeed XML feed.

 

[info]

<?php

function curl_request(){

// Get cURL resource

$curl = curl_init();

// Set some options

curl_setopt_array($curl, array(

// Return the response as a string instead of outputting it to the screen

CURLOPT_RETURNTRANSFER => 1,

//URL to send request to

CURLOPT_URL => ‘http://api.indeed.com/ads/apisearch?publisher=9xxxxxxxxxxxxxxx&q=php&l=austin%2C+tx&sort=&radius=&st=&jt=&start=&limit=100&fromage=&filter=&latlong=1&co=us&chnl=&userip=1.2.3.4&useragent=Mozilla/%2F4.0%28Firefox%29&v=2‘,));

// Send the request & save response to $resp

$resp = curl_exec($curl);

//print($resp);

// Close request to clear up some resources

curl_close($curl);

return $resp;

}

?>
[/info]

Step 4 : Create a function that convert XML to Array

Using the api URL we only gets the xml data. This need to be converted to an array and we need to create a function for that.

Example for XML feed

[error]

<?xml version=”1.0″ encoding=”UTF-8″ ?>
<response version=”2″>
<query>java</query>
<location>austin, tx</location>
<dupefilter>true</dupefilter>
<highlight>false</highlight>
<totalresults>547</totalresults>
<start>1</start>
<end>10</end>
<radius>25</radius>
<pageNumber>0</pageNumber>
<results>
<result>
<jobtitle>Java Developer</jobtitle>
<company>XYZ Corp.</company>
<city>Austin</city>
<state>TX</state>
<country>US</country>
<formattedLocation>Austin, TX</formattedLocation>
<source>Dice</source>
<date>Mon, 02 Aug 2010 16:21:00 GMT</date>
<snippet>looking for an object-oriented Java Developer… Java Servlets, HTML, JavaScript,
AJAX, Struts, Struts2, JSF) desirable. Familiarity with Tomcat and the Java…</snippet>
<url>http://www.indeed.com/viewjob?jk=12345&indpubnum=8343699265155203</url>
<onmousedown>indeed_clk(this,’0000′);</onmousedown>
<latitude>30.27127</latitude>
<longitude>-97.74103</longitude>
<jobkey>12345</jobkey>
<sponsored>false</sponsored>
<expired>false</expired>
<formattedLocationFull>Austin, TX</formattedLocationFull>
<formattedRelativeTime>11 hours ago</formattedRelativeTime>
</result>

</results>
</response>

[/error]

 

Function

[info]

<?php

function xmlToArray($input, $callback = null, $recurse = false) {

$data = ((!$recurse) && is_string($input))? simplexml_load_string($input, ‘SimpleXMLElement’, LIBXML_NOCDATA): $input;

if ($data instanceof SimpleXMLElement) $data = (array) $data;

if (is_array($data)) foreach ($data as &$item) $item = xmlToArray($item, $callback, true);

return (!is_array($data) && is_callable($callback))? call_user_func($callback, $data): $data;

}

?>
[/info]

Step 5: Create a webpage “indeed.php”

 

We create a web page to include all the functions that we created above.

 

[success]

<?php

function curl_request(){

// Get cURL resource

$curl = curl_init();

// Set some options

curl_setopt_array($curl, array(

// Return the response as a string instead of outputting it to the screen

CURLOPT_RETURNTRANSFER => 1,

//URL to send request to

CURLOPT_URL => ‘http://api.indeed.com/ads/apisearch?publisher=9xxxxxxxxxxxxxxx&q=php&l=austin%2C+tx&sort=&radius=&st=&jt=&start=&limit=25&fromage=&filter=&latlong=1&co=us&chnl=&userip=1.2.3.4&useragent=Mozilla/%2F4.0%28Firefox%29&v=2‘,

));

// Send the request & save response to $resp

$resp = curl_exec($curl);

// Close request to clear up some resources

curl_close($curl);

return $resp;

}

 

function xmlToArray($input, $callback = null, $recurse = false) {

$data = ((!$recurse) && is_string($input))? simplexml_load_string($input, ‘SimpleXMLElement’, LIBXML_NOCDATA): $input;

if ($data instanceof SimpleXMLElement) $data = (array) $data;

if (is_array($data)) foreach ($data as &$item) $item = xmlToArray($item, $callback, true);

return (!is_array($data) && is_callable($callback))? call_user_func($callback, $data): $data;

}

?>

<html>

<body>

<ol>

<?php

for($i=0;$i<25;$i++){    // using for loop to show number of  jobs

$resp=curl_request($i);

$arrXml = xmlToArray($resp);

$results=$arrXml[‘results’];

?>

<li>

<p>

<strong>Job :<a href=”<?php echo $results[‘result’][$i][‘url’]; ?>” target=”_blank”><?php echo $results[‘result’][$i][‘jobtitle’]; ?></a></strong>

</p>

<p><strong>Location: <?php echo $results[‘result’][$i][‘city’]; ?></strong></p>

<p><strong>Date :<?php echo $results[‘result’][$i][‘date’];?></strong></p>

<p> Descriptions :<?php echo $results[‘result’][$i][‘snippet’]; ?></p>

</li>

<?php } ?>

</ol>

</body>

</html>
[/success]

Step 6 : Create a page index.php with indeed link to load job feeds.

This is the home page that shows the link to indeed.php which displays jobs from indeed site.

 

[success]

<html>

<body>

<p>

Show jobs from <a href=”indeed.php”>INDEED</a>

</p>

</body>

</html>
[/success]

After creating these two files please save it in a single folder in the local host or server. Below is the screen shot of webpage that loads indeed jobs.

php codes to load job feeds

screen shot of the web page

One thought on “How To Show Job Feeds From Indeed Using PHP code”

  1. Thanks for this post……could you please provide a little more detail on how to set this up? I’m confused on what back-end files to create, what to name them and where to put them in the WordPress theme directory. Also, how would I set this up to pass a different location for each WordPress post? For example, if I wanted to have a post for Chicago and another for Boston, how would I create variables to pass the different locations on each post?

    Thanks!

Comments are closed.