Client Helper
The Twitch4J Client Helper aims to bundle some common code used by library users to prevent everyone from reinventing the wheel ;)
Current Features:
- Stream Updates:
ChannelGoLiveEvent
,ChannelGoOfflineEvent
,ChannelChangeGameEvent
,ChannelChangeTitleEvent
,ChannelViewerCountUpdateEvent
- Clip Updates:
ChannelClipCreatedEvent
- Follower Updates:
FollowEvent
,ChannelFollowCountUpdateEvent
Those methods require the Helix Module
, so enable it in the TwitchClientBuilder
.
Default Credential
Since the client helper makes Helix API calls, you must include a form of authorization when building the client.
In particular, you can pass an app access token or user access token to withDefaultAuthToken
,
or specify both withClientId
/withClientSecret
for the library to automatically generate an app access token.
However, for FollowEvent
, you will need to specify a user access token of a moderator of the target channel
with the moderator:read:followers
scope, due to Twitch shutting down the (more permissive) legacy follows API in September 2023.
- Java
- Kotlin
- Groovy
ITwitchClient twitchClient = TwitchClientBuilder.builder()
.withDefaultAuthToken(new OAuth2Credential("twitch", "oauthtokenhere"))
.build();
val twitchClient = TwitchClientBuilder.builder()
.withDefaultAuthToken(OAuth2Credential("twitch", "oauthtokenhere"))
.build();
def twitchClient = TwitchClientBuilder.builder()
.withDefaultAuthToken(new OAuth2Credential("twitch", "oauthtokenhere"))
.build();
Register for Stream Live/Offline/Category/Title Events
Allows ChannelGoLiveEvent
, ChannelGoOfflineEvent
, ChannelChangeGameEvent
, ChannelChangeTitleEvent
, ChannelViewerCountUpdateEvent
to be fired.
- Java
- Kotlin
- Groovy
twitchClient.getClientHelper().enableStreamEventListener("twitch4j");
twitchClient.clientHelper.enableStreamEventListener("twitch4j");
twitchClient.clientHelper.enableStreamEventListener("twitch4j");
Register for Follow Event
Note: ChannelFollowCountUpdateEvent
will fire for any user or app access token.
For FollowEvent
, you must specify withDefaultAuthToken
with a user access token (scope: moderator:read:followers
)
that represents a moderator of the target channel.
- Java
- Kotlin
- Groovy
twitchClient.getClientHelper().enableFollowEventListener("twitch4j");
twitchClient.clientHelper.enableFollowEventListener("twitch4j");
twitchClient.clientHelper.enableFollowEventListener("twitch4j");
Register for Clip Events
Allows ChannelClipCreatedEvent
to be fired.
- Java
- Kotlin
- Groovy
twitchClient.getClientHelper().enableClipEventListener("twitch4j");
twitchClient.clientHelper.enableClipEventListener("twitch4j");
twitchClient.clientHelper.enableClipEventListener("twitch4j");