Create an account at newsapi.org to get your API key.
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
implementation 'com.github.KwabenBerko:News-API-Java:1.0.2'
NewsApiClient newsApiClient = new NewsApiClient("YOUR_API_KEY");
newsApiClient.getTopHeadlines(
new TopHeadlinesRequest.Builder()
.q("bitcoin")
.language("en")
.build(),
new NewsApiClient.ArticlesResponseCallback() {
@Override
public void onSuccess(ArticleResponse response) {
System.out.println(response.getArticles().get(0).getTitle());
}
@Override
public void onFailure(Throwable throwable) {
System.out.println(throwable.getMessage());
}
}
);
newsApiClient.getEverything(
new EverythingRequest.Builder()
.q("trump")
.build(),
new NewsApiClient.ArticlesResponseCallback() {
@Override
public void onSuccess(ArticleResponse response) {
System.out.println(response.getArticles().get(0).getTitle());
}
@Override
public void onFailure(Throwable throwable) {
System.out.println(throwable.getMessage());
}
}
);
newsApiClient.getSources(
new SourcesRequest.Builder()
.language("en")
.country("us")
.build(),
new NewsApiClient.SourcesCallback() {
@Override
public void onSuccess(SourcesResponse response) {
System.out.println(response.getSources().get(0).getName());
}
@Override
public void onFailure(Throwable throwable) {
System.out.println(throwable.getMessage());
}
}
);