- Fixed bug: WebcastSocialMessage was always triggering `TikTokShareEvent` events such as `TikTokLikeEvent`, `TikTokFollowEvent`, `TikTokShareEvent`, `TikTokJoinEvent` was ignored
TikTok-Live-Java
A Java library based on TikTok-Connector 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.
Do you prefer other programming languages?
- Node orginal: TikTok-Live-Connector by @isaackogan
- 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.
Overview
Getting started
- 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.13-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();
}
Configuration
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();
}
}
Methods
A client (LiveClient) object contains the following methods.
| Method Name | Description |
|---|---|
| connect | Connects to the live stream chat. Returns a Promise which will be resolved when the connection is successfully established. |
| disconnect | Disconnects the connection. |
| getGiftManager | Gets the meta informations about all gifts. |
| getRoomInfo | Gets the current room info from TikTok API including streamer info, room status and statistics. |
Events
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
Contributing
Your improvements are welcome! Feel free to open an issue or pull request.