|

|  How to Fetch Job Data Using Indeed API in Java

How to Fetch Job Data Using Indeed API in Java

October 31, 2024

Learn to retrieve job listings with the Indeed API in Java. Step-by-step guide for seamless integration, ensuring efficient data fetching for your application.

How to Fetch Job Data Using Indeed API in Java

 

Set Up HTTP Client in Java

 

  • Use the `OkHttp` library, a popular choice for making HTTP requests in Java due to its simplicity and efficiency.
  •  

  • Add necessary dependencies to your `pom.xml` if you're using Maven, or update your Gradle configuration accordingly.

 

<dependency>
    <groupId>com.squareup.okhttp3</groupId>
    <artifactId>okhttp</artifactId>
    <version>4.9.3</version>
</dependency>

 

Configure the Indeed API Endpoint

 

  • Indeed API's base URL typically requires you to specify parameters for authentication, location, job type, etc.
  •  

  • Example parameters include `publisher`, `v` (version), `q` (query), `l` (location), `sort`, and more.

 

Implement the Java Class for Fetching Jobs

 

  • Create a Java class that handles the construction and execution of an HTTP GET request to the Indeed API.
  •  

  • Utilize `OkHttpClient` for creating requests and handling the API's JSON responses.

 

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.json.JSONObject;
import org.json.JSONArray;

public class IndeedJobFetcher {
    private static final String BASE_URL = "https://api.indeed.com/ads/apisearch";

    public String fetchJobs(String publisherId, String query, String location) {
        OkHttpClient client = new OkHttpClient();
        String url = BASE_URL + "?publisher=" + publisherId +
                     "&q=" + query + "&l=" + location + "&v=2";

        Request request = new Request.Builder()
                .url(url)
                .build();

        try (Response response = client.newCall(request).execute()) {
            if (response.isSuccessful()) {
                return response.body().string();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}

 

Parse the JSON Response

 

  • Use the `org.json` library to parse the JSON response returned from the API.
  •  

  • Identify the keys within the JSON structure that contain job information like job title, company name, location, and others.

 

public void parseJobData(String jsonData) {
    try {
        JSONObject jsonObject = new JSONObject(jsonData);
        JSONArray results = jsonObject.getJSONArray("results");

        for (int i = 0; i < results.length(); i++) {
            JSONObject job = results.getJSONObject(i);
            String jobTitle = job.getString("jobtitle");
            String companyName = job.getString("company");
            String jobLocation = job.getString("formattedLocation");
            System.out.println(jobTitle + " at " + companyName + " in " + jobLocation);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

 

Integrate and Execute the Job Fetcher

 

  • Incorporate the `IndeedJobFetcher` class within a main method to call the API with appropriate parameters.
  •  

  • Ensure the fetched job data is parsed and displayed or further processed according to your specific application needs.

 

public class Main {
    public static void main(String[] args) {
        IndeedJobFetcher jobFetcher = new IndeedJobFetcher();
        String jsonResponse = jobFetcher.fetchJobs("yourPublisherId", "software developer", "new york");

        if (jsonResponse != null) {
            jobFetcher.parseJobData(jsonResponse);
        }
    }
}

 

Pre-order Friend AI Necklace

Pre-Order Friend Dev Kit

Open-source AI wearable
Build using the power of recall

Order Now

OMI AI PLATFORM
Remember Every Moment,
Talk to AI and Get Feedback

Omi Necklace

The #1 Open Source AI necklace: Experiment with how you capture and manage conversations.

Build and test with your own Omi Dev Kit 2.

Omi App

Fully Open-Source AI wearable app: build and use reminders, meeting summaries, task suggestions and more. All in one simple app.

Github →

Join the #1 open-source AI wearable community

Build faster and better with 3900+ community members on Omi Discord

Participate in hackathons to expand the Omi platform and win prizes

Participate in hackathons to expand the Omi platform and win prizes

Get cash bounties, free Omi devices and priority access by taking part in community activities

Join our Discord → 

OMI NECKLACE + OMI APP
First & only open-source AI wearable platform

a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded
a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded
online meeting with AI Wearable, showcasing how it works and helps online meeting with AI Wearable, showcasing how it works and helps
online meeting with AI Wearable, showcasing how it works and helps online meeting with AI Wearable, showcasing how it works and helps
App for Friend AI Necklace, showing notes and topics AI Necklace recorded App for Friend AI Necklace, showing notes and topics AI Necklace recorded
App for Friend AI Necklace, showing notes and topics AI Necklace recorded App for Friend AI Necklace, showing notes and topics AI Necklace recorded

OMI NECKLACE: DEV KIT
Order your Omi Dev Kit 2 now and create your use cases

Omi Dev Kit 2

Endless customization

OMI Necklace

$69.99

Make your life more fun with your AI wearable clone. It gives you thoughts, personalized feedback and becomes your second brain to discuss your thoughts and feelings. Available on iOS and Android.

Your Omi will seamlessly sync with your existing omi persona, giving you a full clone of yourself – with limitless potential for use cases:

  • Real-time conversation transcription and processing;
  • Develop your own use cases for fun and productivity;
  • Hundreds of community apps to make use of your Omi Persona and conversations.

Learn more

Omi Dev Kit 2: build at a new level

Key Specs

OMI DEV KIT

OMI DEV KIT 2

Microphone

Yes

Yes

Battery

4 days (250mAH)

2 days (250mAH)

On-board memory (works without phone)

No

Yes

Speaker

No

Yes

Programmable button

No

Yes

Estimated Delivery 

-

1 week

What people say

“Helping with MEMORY,

COMMUNICATION

with business/life partner,

capturing IDEAS, and solving for

a hearing CHALLENGE."

Nathan Sudds

“I wish I had this device

last summer

to RECORD

A CONVERSATION."

Chris Y.

“Fixed my ADHD and

helped me stay

organized."

David Nigh

OMI NECKLACE: DEV KIT
Take your brain to the next level

LATEST NEWS
Follow and be first in the know

Latest news
FOLLOW AND BE FIRST IN THE KNOW

team@basedhardware.com

company

about

careers

invest

privacy

products

omi

omi dev kit

personas

resources

apps

affiliate

docs

github

help