Java SDK provides access to the News API v3 from Java or Kotlin applications.

Installation

Gradle

dependencies {
    implementation 'com.newscatcherapi:newscatcher-sdk:1.1.0'
}

Maven

<dependency>
    <groupId>com.newscatcherapi</groupId>
    <artifactId>newscatcher-sdk</artifactId>
    <version>1.1.0</version>
</dependency>

Basic usage

import com.newscatcher.api.NewscatcherApiClient;
import com.newscatcher.api.resources.search.requests.SearchPostRequest;
import java.util.Arrays;

NewscatcherApiClient client = NewscatcherApiClient.builder()
    .apiKey("YOUR_API_KEY")
    .build();

client.search().post(SearchPostRequest.builder()
    .q("renewable energy")
    .lang(Arrays.asList("en"))
    .build());

Error handling

import com.newscatcher.api.core.NewscatcherApiApiException;

try {
    client.search().post(...);
} catch (NewscatcherApiApiException e) {
    System.out.println(e.getMessage());
    System.out.println(e.statusCode());
    System.out.println(e.body());
}

For complete documentation, including specific error types and configuration options, see the GitHub repository.

If you use our legacy Java SDK (Konfig-based), see our Legacy SDKs documentation. We recommend migrating to this newer SDK for improved features and ongoing support.

Resources