A comprehensive Java library for interacting with the Kick.com streaming platform API. Kick4j provides easy-to-use clients for all major Kick API endpoints, OAuth 2.0 authentication with PKCE support, and built-in webhook handling for real-time events.
- Complete API Coverage: Support for all official Kick.com API endpoints
- User management and authentication
- Channel operations and metadata
- Chat messaging
- Livestream management
- Moderation tools
- Categories and discovery
- Event subscriptions
- OAuth 2.0 with PKCE: Secure authentication flow implementation
- Webhook Support: Built-in webhook receiver with signature verification, for demonstration purposes
- Event System: Type-safe event handling for real-time notifications
- Flexible Configuration: Customizable endpoints and settings
- Token Management: Automatic token refresh and storage
Add the repository to your build.gradle
or build.gradle.kts
:
repositories {
mavenCentral()
maven {
name = "teksusik"
url = "https://repo.teksusik.pl/snapshots"
}
}
dependencies {
implementation 'pl.teksusik:kick4j:1.1.0-SNAPSHOT'
}
Add the repository to your pom.xml
:
<repositories>
<repository>
<id>teksusik</id>
<url>https://repo.teksusik.pl/snapshots</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>pl.teksusik</groupId>
<artifactId>kick4j</artifactId>
<version>1.1.0-SNAPSHOT</version>
</dependency>
</dependencies>
import pl.teksusik.kick4j.KickClient;
import pl.teksusik.kick4j.KickConfiguration;
import pl.teksusik.kick4j.authorization.FileRefreshTokenStore;
// Configure the client
KickConfiguration config = KickConfiguration.builder()
.clientId("your-client-id")
.clientSecret("your-client-secret")
.redirectUri("http://localhost:8080/callback")
.tokenStore(new FileRefreshTokenStore(Paths.get("refresh_token.txt")))
.build();
// Create the client
KickClient client = new KickClient(config);
import pl.teksusik.kick4j.authorization.Scope;
import static pl.teksusik.kick4j.authorization.AuthorizationClient.*;
// Generate PKCE codes
String codeVerifier = generateCodeVerifier();
String codeChallenge = generateCodeChallenge(codeVerifier);
// Get authorization URL
String authUrl = client.authorization().getAuthorizationUrl(
List.of(Scope.USER_READ, Scope.CHANNEL_READ, Scope.CHAT_WRITE),
codeChallenge
);
System.out.println("Visit: " + authUrl);
// After user authorization, exchange code for tokens
String authCode = "code-from-callback";
OAuthTokenResponse tokens = client.authorization()
.exchangeCodeForToken(authCode, codeVerifier);
client.authorization().setTokens(tokens);
// Get current user
User currentUser = client.users().getCurrentUser();
System.out.println("Hello, " + currentUser.getName());
// Get current channel
Channel channel = client.channels().getCurrentChannel();
System.out.println("Channel: " + channel.getSlug());
// Send a chat message
PostChatMessageRequest chatRequest = PostChatMessageRequest.builder()
.broadcastUserId(channel.getBroadcasterUserId())
.content("Hello from Kick4j!")
.type(PostChatMessageRequest.Type.BOT)
.build();
client.chat().postChatMessage(chatRequest);
// Update channel information
UpdateChannelRequest updateRequest = UpdateChannelRequest.builder()
.streamTitle("New Stream Title")
.categoryId(12)
.build();
client.channels().updateChannel(updateRequest);
Kick4j provides built-in webhook support for handling real-time events:
// Register event listeners
client.eventDispatcher().registerListener(
ChatMessageSentEvent.class,
event -> {
System.out.println(event.getSender().getUsername() +
" said: " + event.getContent());
}
);
client.eventDispatcher().registerListener(
ChannelFollowedEvent.class,
event -> {
System.out.println("New follower: " +
event.getFollower().getUsername());
}
);
// Start webhook receiver
client.startWebhookReceiver("/webhooks", 8080);
// Subscribe to events
EventSubscriptionRequest subscription = EventSubscriptionRequest.builder()
.broadcasterUserId(currentUser.getUserId())
.addEvent(new EventSubscriptionRequest.Event("chat.message.sent", 1))
.addEvent(new EventSubscriptionRequest.Event("channel.followed", 1))
.method(EventSubscriptionRequest.Method.WEBHOOK)
.build();
client.events().postEventsSubscription(subscription);
chat.message.sent
- New chat messageschannel.followed
- New followerschannel.subscription.new
- New subscriptionschannel.subscription.renewal
- Subscription renewalschannel.subscription.gifts
- Gift subscriptionslivestream.status.updated
- Stream start/stoplivestream.metadata.updated
- Stream title/category changesmoderation.banned
- User bans/timeouts
// Ban a user
PostModerationBansRequest banRequest = PostModerationBansRequest.builder()
.broadcasterUserId(channel.getBroadcasterUserId())
.userId(123456)
.duration(3600)
.reason("Spam")
.build();
client.moderation().postModerationBans(banRequest);
// Unban a user
client.moderation().deleteModerationBans(
channel.getBroadcasterUserId(),
123456
);
// Get current livestream
Livestream stream = client.livestreams()
.getLivestream(channel.getBroadcasterUserId());
if (stream != null) {
System.out.println("Currently streaming: " + stream.getStreamTitle());
System.out.println("Viewers: " + stream.getViewerCount());
}
// Search livestreams
GetLivestreamsRequest searchRequest = GetLivestreamsRequest.builder()
.category(12) // Gaming
.language("en")
.limit(10)
.sort(GetLivestreamsRequest.Sort.VIEWER_COUNT)
.build();
List<Livestream> streams = client.livestreams().getLivestreams(searchRequest);
// Search categories
List<Category> categories = client.categories().getCategories("gaming");
// Get specific category
Category category = client.categories().getCategory(12);
System.out.println("Category: " + category.getName());
Implement the RefreshTokenStore
interface for custom token storage:
public class DatabaseTokenStore implements RefreshTokenStore {
@Override
public String getRefreshToken() {
// Retrieve from database
return database.getRefreshToken();
}
@Override
public void notifyRefreshTokenRoll(String newRefreshToken) {
// Store in database
database.saveRefreshToken(newRefreshToken);
}
}
KickConfiguration config = KickConfiguration.builder()
.clientId("your-client-id")
.clientSecret("your-client-secret")
.redirectUri("https://your-app.com/callback")
.tokenStore(new DatabaseTokenStore())
.baseUrl("https://api.kick.com/public/v1") // Custom API base URL
.oAuthHost("https://id.kick.com") // Custom OAuth host
.build();
Kick4j throws specific exceptions for different error conditions:
try {
User user = client.users().getCurrentUser();
} catch (ApiException e) {
System.err.println("API Error " + e.getErrorCode() + ": " + e.getPayload());
} catch (OAuthTokenException e) {
System.err.println("Auth Error " + e.getErrorCode() + ": " + e.getPayload());
// Handle token refresh or re-authentication
}
- Java 21 or higher
- Valid Kick.com application credentials
- Jackson (JSON processing)
- Java HTTP Client (built-in)
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For questions, issues, or feature requests, please open an issue on the GitHub repository.
This library is not officially affiliated with Kick.com. Use at your own risk and ensure compliance with Kick.com's Terms of Service and API usage guidelines.