A Java library based on TikTokLive and TikTokLiveSharp. Use it to receive live stream events such as comments and gifts in realtime from TikTok LIVE by connecting to TikTok's internal WebCast push service. The package includes a wrapper that connects to the WebCast service using just the username (uniqueId). This allows you to connect to your own live chat as well as the live chat of other streamers. No credentials are required. Besides Chat Comments, other events such as Members Joining, Gifts, Subscriptions, Viewers, Follows, Shares, Questions, Likes and Battles can be tracked. You can also send automatic messages into the chat by providing your Session ID.
Join the support discord and visit the #java-support channel for questions, contributions and ideas. Feel free to make pull requests with missing/new features, fixes, etc
Do you prefer other programming languages?
- Node orginal: TikTok-Live-Connector by @zerodytrash
- Python rewrite: TikTokLive by @isaackogan
- Go rewrite: GoTikTokLive by @Davincible
- C# rewrite: TikTokLiveSharp by @frankvHoof93
NOTE: This is not an official API. It's a reverse engineering project.
- Install the package via Maven
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories> <dependencies>
<dependency>
<groupId>com.github.jwdeveloper.TikTok-Live-Java</groupId>
<artifactId>Client</artifactId>
<version>0.0.14-Release</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>
</dependencies>- Create your first chat connection
public static void main(String[] args)
{
// Username of someone who is currently live
var tiktokUsername = "jwdevtiktok";
TikTokLive.newClient(tiktokUsername)
.onConnected((client, event) ->
{
System.out.println("Connected");
})
.onJoin((client, event) ->
{
System.out.println("User joined -> " + event.getUser().getNickName());
})
.onComment((client, event) ->
{
System.out.println(event.getUser().getUniqueId() + ": " + event.getText());
})
.onEvent((client, event) ->
{
System.out.println("Viewers count: "+client.getRoomInfo().getViewersCount());
})
.onError((client, event) ->
{
event.getException().printStackTrace();
})
.buildAndRun();
System.in.read();
}public class ConfigurationExample
{
public static void main(String[] args) throws IOException {
var tiktokUsername = "jwdevtiktok";
TikTokLive.newClient(tiktokUsername)
.configure(clientSettings ->
{
clientSettings.setHostName(Main.TEST_TIKTOK_USER); // TikTok user name
clientSettings.setClientLanguage("en"); // Language
clientSettings.setTimeout(Duration.ofSeconds(2)); // Connection timeout
clientSettings.setLogLevel(Level.ALL); // Log level
clientSettings.setDownloadGiftInfo(true); // Downloading meta information about gifts. You can access it by client.getGiftManager().getGiftsInfo();
clientSettings.setPrintMessageData(true); // Printing TikTok Protocol buffer messages in Base64 format
clientSettings.setPrintToConsole(true); // Printing all logs to console even if log level is Level.OFF
clientSettings.setHandleExistingMessagesOnConnect(true); // Invokes all TikTok events that had occurred before connection
clientSettings.setRetryOnConnectionFailure(true); // Reconnecting if TikTok user is offline
clientSettings.setRetryConnectionTimeout(Duration.ofSeconds(1)); // Timeout before next reconnection
})
.buildAndRun();
System.in.read();
}
}A client (LiveClient) object contains the following methods.
| Method Name | Description |
|---|---|
| connect | Connects to the live stream. |
| disconnect | Disconnects the connection. |
| sendHeartbeat | Sends a heartbeat to the WebSocketClient. |
| getGiftManager | Gets the meta informations about all gifts. |
| getRoomInfo | Gets the current room info from TikTok API including streamer info, room status and statistics. |
A TikTokLive object has the following events
Events:
- TikTokUnhandledSocialEvent
- TikTokLinkMicFanTicketEvent
- TikTokEnvelopeEvent
- TikTokShopMessageEvent
- TikTokDetectMessageEvent
- TikTokLinkLayerMessageEvent
- TikTokConnectedEvent
- TikTokCaptionEvent
- TikTokQuestionEvent
- TikTokRoomPinMessageEvent
- TikTokRoomMessageEvent
- TikTokLivePausedEvent
- TikTokLikeEvent
- TikTokLinkMessageEvent
- TikTokBarrageMessageEvent
- TikTokGiftMessageEvent
- TikTokLinkMicArmiesEvent
- TikTokEmoteEvent
- TikTokUnauthorizedMemberEvent
- TikTokInRoomBannerEvent
- TikTokLinkMicMethodEvent
- TikTokSubscribeEvent
- TikTokPollMessageEvent
- TikTokFollowEvent
- TikTokRoomViewerDataEvent
- TikTokGoalUpdateEvent
- TikTokCommentEvent
- TikTokRankUpdateEvent
- TikTokIMDeleteEvent
- TikTokLiveEndedEvent
- TikTokErrorEvent
- TikTokUnhandledEvent
- TikTokJoinEvent
- TikTokRankTextEvent
- TikTokShareEvent
- TikTokUnhandledMemberEvent
- TikTokSubNotifyEvent
- TikTokLinkMicBattleEvent
- TikTokDisconnectedEvent
- TikTokGiftBroadcastEvent
- TikTokUnhandledControlEvent
- TikTokEvent
Your improvements are welcome! Feel free to open an issue or pull request.