Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Java implementation of TikTok-Live-Connector library. Receive live stream events (comments, gifts, etc.) in realtime from TikTok LIVE.

Notifications You must be signed in to change notification settings

Draxwere/TikTokLiveJava

 
 

Repository files navigation

TikTokLive Java

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?

NOTE: This is not an official API. It's a reverse engineering project.

Overview

Getting started

  1. 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>
  1. 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.
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.

Events

A TikTokLive object has the following events

Events:



Contributing

Your improvements are welcome! Feel free to open an issue or pull request.

About

Java implementation of TikTok-Live-Connector library. Receive live stream events (comments, gifts, etc.) in realtime from TikTok LIVE.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 99.7%
  • Shell 0.3%