Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.Webhose:webhoseio-java-sdk:'
}
dependencies {
implementation("com.github.Webhose:webhoseio-java-sdk:")
}
<dependency>
<groupId>com.github.Webhose</groupId>
<artifactId>webhoseio-java-sdk</artifactId>
<version></version>
</dependency>
libraryDependencies += "com.github.Webhose" % "webhoseio-java-sdk" % ""
:dependencies [[com.github.Webhose/webhoseio-java-sdk ""]]
A simple way to access the webz.io API from your Java code
// Create a WebzIOClient instance
WebzIOClient webzClient = WebzIOClient.getInstance(API_KEY);
// Create set of queries
Map<String, String> queries = new HashMap<String, String>();
queries.put("q", "github");
// Fetch query result
JsonElement result = webzClient.query("filterWebContent", queries);
System.out.println(result.getAsJsonObject().get("totalResults")); // Print posts count
To make use of the webz.io API, you need to obtain a token that would be used on every request. To obtain an API key, create an account at https://webz.io/auth/signup, and then go into https://webz.io/dashboard to see your token.
To get started, you need to import the library, and set your access token. (Replace YOUR_API_KEY with your actual API key).
import com.webz.sdk.WebzIOClient;
WebzIOClient webzClient = WebzIOClient.getInstance(API_KEY);
Now you can make a request and inspect the results:
// Create set of queries
Map<String, String> queries = new HashMap<String, String>();
queries.put("q", "foobar");
JsonElement result = webzClient.query("filterWebContent", queries);
System.out.println(result.getAsJsonObject().get("totalResults")); // Print posts count
JsonArray postArray = result.getAsJsonObject().getAsJsonArray("posts");
for(JsonElement o : postArray) {
System.out.println(o.getAsJsonObject().get("title")); // Print title
System.out.println(o.getAsJsonObject().get("author")); // Print author
System.out.println(o.getAsJsonObject().get("language")); // Print language
}
API Endpoints
The first parameter the Query
function accepts is the API endpoint string. Available endpoints:
filterWebContent
- access to the news/blogs/forums/reviews APIproductFilter
- access to data about eCommerce products/servicesdarkFilter
- access to the dark web (coming soon)getInstance(token) Initialize WebzIOClient and return an instance.
WebzIOClient webzClient = WebzIOClient.getInstance(TOKEN);
token
- your API keyquery(endpoint, queries) Convenient method to query a specific keyword. Returns JSONObject instance.
// Create set of queries
Map<String, String> queries = new HashMap<String, String>();
queries.put("q", "github"); // Query using keyword "github"
queries.put("size", "3"); // (OPTIONAL) Limit response to maximum of 3 items
// Fetch query result
JsonElement result = webzClient.query("filterWebContent", queries);
System.out.println(result.getAsJsonObject().get("totalResults")); // Print posts count
JsonArray postArray = result.getAsJsonObject().getAsJsonArray("posts");
for(JsonElement o : postArray) {
System.out.println(o.getAsJsonObject().get("title")); // Print title
System.out.println(o.getAsJsonObject().get("author")); // Print author
System.out.println(o.getAsJsonObject().get("language")); // Print language
}
filterWebContent
- access to the news/blogs/forums/reviews APIcyberFilter
- access to the dark web/cyber APInseFilter
- access to the enriched news APIreviewFilter
- access to the reviews APIdbdocFilter
- access to the breach detection APIgovFilter
- access to the government data APInbdSeg
- access to the news/blogs/forums/reviews data segmentation APIenaSeg
- access to the enriched news data segmentation APIreviewSeg
- access to the reviews data segmentation APIcyberSeg
- access to the dark web/cyber data segmentation APIgetNext() Convenient method to fetch next query page. Returns JSONObject instance.
JsonElement result = webzClient.getNext();
System.out.println(result.getAsJsonObject().get("totalResults")); // Print posts count
JsonArray postArray = result.getAsJsonObject().getAsJsonArray("posts");
for(JsonElement o : postArray) {
System.out.println(o.getAsJsonObject().get("title")); // Print title
System.out.println(o.getAsJsonObject().get("author")); // Print author
System.out.println(o.getAsJsonObject().get("language")); // Print language
}