/twitch4j

This is a api client for the Twitch API V5/IRC/PubSub.

Primary LanguageJavaMIT LicenseMIT

Build Status Average time to resolve an issue Percentage of issues still open Download

Java API for Twitch

Support:

Discord Server

Twitch API Server

Documentation:

Javadocs Wiki


A quick note:

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.

Quick Start

Gradle

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'
}

Maven

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>

Features

OAuth Authentication

  • Twitch
  • StreamLabs

Twitch REST Endpoints

  • Bits
  • Channel Feed #50
  • Channels
  • Chat
  • Clips
  • Collections
  • Communities (Released: 10.02.2017)
  • Games
  • Ingests
  • Search
  • Streams
  • Teams
  • Users
  • Videos

Twitch PubSub

  • Bits
  • Whispers
  • Subscriptions
  • Stream Status - Unofficial
  • Moderation Action (from specified moderator in specified channel) - Unofficial

Twitch IRC (WebSocket)

  • 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

3rd Party

  • Users (Read)
  • Donations (Read, Create)
  • Custom Alerts (Create)
  • Planned
  • Planned
  • No API
  • No API

Getting Started

Just some simple examples, visit the WIKI for more details.

Sample Projects using Twitch4J

Client Builder (Twitch Standalone)

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();

Get User Id from UserName

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
}

Get Channel Follows

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();
}

WIKI

For more advanced features, check out the WIKI.

Problems

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.

License

Released under the MIT license.