Java API for Twitch
Support:
Documentation:
This API aims to retrieve all twitch relation information from the Twitch REST API V5, Twitch PubSub and the Twitch IRC Server. Futhermore twitch related services like Streamlabs are integrated.
This project is still in development, check out Features and Changelog to follow progress.
Add it to your build.gradle with:
repositories {
jcenter()
}
and: (latest, you should use the actual version here)
dependencies {
compile 'com.github.twitch4j:twitch4j:v0.11.0'
}
Add it to your pom.xml with:
<repositories>
<repository>
<id>jcenter</id>
<url>https://jcenter.bintray.com/</url>
</repository>
</repositories>
and: (latest, you should use the actual version here)
<dependency>
<groupId>com.github.twitch4j</groupId>
<artifactId>twitch4j</artifactId>
<version>v0.11.0</version>
</dependency>
- Twitch
- StreamLabs
- Bits
-
Channel Feed#50 - Channels
- Chat
- Clips
- Collections
- Communities (Released: 10.02.2017)
- Games
- Ingests
- Search
- Streams
- Teams
- Users
- Videos
- Bits
- Whispers
- Subscriptions
- Stream Status - Unofficial
- Moderation Action (from specified moderator in specified channel) - Unofficial
- Subscriptions
- Cheers (Bits)
-
/me
interactions chat -
/color
changer - Moderation
- Ban (with reason)
- Timeout (with reason)
- Slow mode
- Sub mode
- Follow mode
- R9K mode
- Emote Only mode
- Channel Editor
- Commercial
- Host mode
- Users (Read)
- Donations (Read, Create)
- Custom Alerts (Create)
- Planned
- Planned
- No API
- No API
Just some simple examples, visit the WIKI for more details.
- CLI: Chatbot - Twitch4J by @twitch4j
- GUI: Twitch Queue Bot by @SirSkaro
TwitchClient twitchClient = TwitchClientBuilder.init()
.withClientId("Twitch App Id")
.withClientSecret("Twitch App Secret")
.withAutoSaveConfiguration(true)
.withConfigurationDirectory(new File("config"))
.withCredential("ixsxu9123xzmlx798xooa3f91q1e9c") // Get your token at: https://twitchapps.com/tmi/
.connect();
The Twitch V5 Endpoints prefer to use id's over names. You can get the user/channel id by using the getUserIdByUserName Method of the UserEndpoint.
// Channel Name to Channel ID (V5 API)
Optional<Long> userId = twitchClient.getUserEndpoint().getUserIdByUserName("whynabit");
Because there is the possibility that the user may not exists, you will get an optional return. So you need to handle the result like this:
if (userId.isPresent()) {
// User exists
System.out.println("UserID = " + userId.get());
} else {
// User does not exist -> handle error
}
To extend the above example, the whole code to get the followers of a channel woud look like this:
try {
// Get Channel Endpoint for specific channel
ChannelEndpoint channelEndpoint = twitchClient.getChannelEndpoint("channelName");
// Get the 500 newest followers
List<Follow> followList = channelEndpoint.getFollowers(Optional.ofNullable(500), Optional.ofNullable("desc"));
for(Follow follow : followList) {
System.out.println("User " + follow.getUser().getDisplayName() + " first followed at " + follow.getCreatedAt().toString());
}
} catch (ChannelDoesNotExistException ex) {
System.out.println("Channel does not exist!");
} catch (Exception ex) {
ex.printStackTrace();
}
For more advanced features, check out the WIKI.
If you have problems using the Twitch Java API, then you are welcome to join the discord server to talk about it.
If you discover any issues/have feature requests, then please open an issue here.
Released under the MIT license.