Async Twitch New API Wrapper is a asynchronous java wrapper for interaction with API of the Twitch New API.
Currently support:
- users
- users follows
- streams
- games
Please feel free to report any issues or contribute code.
Using the wrapper is as simple as instantiating the Twitch
object and then calling the appropriate endpoint functions.
For example, a GET /streams/featured
request would map to the twitch.streams().getFeatured()
function; and GET /users/mirrobot
would map to twitch.users().get("mirrobot")
.
Responses are handled via callbacks passed via a handler with each function call. This process is outlined in the following examples.
Twitch twitch = new Twitch();
twitch.setClientId(clientId);
twitch.auth().setAccessToken(accessToken);
twitch.users().get(new UsersResponseHandler() {
@Override
public void onSuccess(final Users users) {
User user = users.getData().get(0);
System.out.println("User: " + user.getLogin());
}
@Override
public void onFailure(int statusCode, String statusMessage, String errorMessage) {
/* Twitch API responded with an error message */
}
@Override
public void onFailure(Throwable e) {
/* Unable to access Twitch, or error parsing the response */
}
});
If you already have an access token, you can explicitly set it. This should not be done prior to an application being distributed as the access token is directly linked to a single Twitch account.
twitch.auth().setAccessToken("my-access-token");
- The Twitch API documentation will best explain the functionality of each endpoint.
- Java Async HTTP Client ver. 2.1.2 // Jar include to the project until it not in the maven repository
- Jackson JSON Processor - Databind ver. 2.9.7
- Apache Commons Lang ver. 3.7
Inspired by Java-Twitch-Api-Wrapper.