JW de27e71e93 Breaking changes:
'Gift': changed from class to enum, so now you can handle
incoming gifts in switch

`Events`
- new:
     onGiftComboFinished
- Removed:
      onGiftBrodcast
- Rename:
     onGiftMessage -> onGift
     onRoomPinMessage -> onRoomPin
     onRoomMessage -> onRoom
     onLinkMessage -> onLink
     onBarrageMessage -> onBarrage
     onPollMessage -> onPoll
     onShopMessage -> onShop
     onDetectMessage -> onDetect

`GiftManager`
   added:
      registerGift
      findById
      findByName
      getGifts
   removed:
      getActiveGifts
2023-10-11 01:20:07 +02:00
2023-09-13 06:38:46 +02:00
2023-10-05 16:56:01 +02:00
2023-10-11 01:20:07 +02:00
2023-10-11 01:20:07 +02:00
2023-10-11 01:20:07 +02:00
2023-10-11 01:20:07 +02:00
2023-10-11 01:20:07 +02:00
2023-10-11 01:20:07 +02:00
2023-10-11 01:20:07 +02:00
2023-09-13 06:32:36 +02:00
2023-08-22 13:54:01 +02:00
2023-09-13 06:48:11 +02:00
2023-08-22 13:54:01 +02:00
2023-10-03 01:44:34 +02:00
2023-10-11 01:20:07 +02:00
2023-10-06 02:31:40 +02:00

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.25-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
package io.github.jwdeveloper.tiktok;
import java.io.IOException;

public class SimpleExample {
    public static void main(String[] args) throws IOException {

        // set tiktok username
        TikTokLive.newClient(Main.TEST_TIKTOK_USER)
                .configure(clientSettings ->
                {

                })
                .onFollow((liveClient, event) ->
                {
                    System.out.println("Follow joined -> " + event.getNewFollower().getNickName());
                })
                .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

package io.github.jwdeveloper.tiktok;

import java.io.IOException;
import java.time.Duration;
import java.util.logging.Level;

public class ConfigurationExample {
    public static void main(String[] args) throws IOException {

        TikTokLive.newClient(Main.TEST_TIKTOK_USER)
                .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

                    //Optional: Sometimes not every message from chat are send to TikTokLiveJava to fix this issue you can set sessionId
                    // documentation how to obtain sessionId https://github.com/isaackogan/TikTok-Live-Connector#send-chat-messages
                    clientSettings.setSessionId("86c3c8bf4b17ebb2d74bb7fa66fd0000");

                    //Optional:
                    clientSettings.setRoomId("XXXXXXXXXXXXXXXXX");
                })
                .buildAndRun();
        System.in.read();
    }
}

Listener Example

package io.github.jwdeveloper.tiktok;

import io.github.jwdeveloper.tiktok.annotations.TikTokEventHandler;
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
import io.github.jwdeveloper.tiktok.data.events.TikTokCommentEvent;
import io.github.jwdeveloper.tiktok.data.events.TikTokErrorEvent;
import io.github.jwdeveloper.tiktok.data.events.TikTokGiftMessageEvent;
import io.github.jwdeveloper.tiktok.data.events.social.TikTokLikeEvent;
import io.github.jwdeveloper.tiktok.listener.TikTokEventListener;
import io.github.jwdeveloper.tiktok.live.LiveClient;

import java.io.IOException;

public class ListenerExample {
    public static void main(String[] args) throws IOException {

        CustomListener customListener = new CustomListener();

        // set tiktok username
        var client = TikTokLive.newClient(Main.TEST_TIKTOK_USER)
                .addListener(customListener)
                .buildAndRun();

        System.in.read();
    }

    /*
       Method in TikTokEventListener should meet 4 requirements to be detected
        - must have @TikTokEventHandler annotation
        - must have 2 parameters
        - first parameter must be LiveClient
        - second must be class that extending TikTokEvent
     */
    public static class CustomListener implements TikTokEventListener {

        @TikTokEventHandler
        public void onLike(LiveClient liveClient, TikTokLikeEvent event) {
            System.out.println(event.toString());
        }

        @TikTokEventHandler
        public void onError(LiveClient liveClient, TikTokErrorEvent event) {
            System.out.println(event.getException().getMessage());
        }

        @TikTokEventHandler
        public void onCommentMessage(LiveClient liveClient, TikTokCommentEvent event) {
            System.out.println(event.getText());
        }

        @TikTokEventHandler
        public void onGiftMessage(LiveClient liveClient, TikTokGiftMessageEvent event) {
            System.out.println(event.getGift().getDescription());
        }

        @TikTokEventHandler
        public void onAnyEvent(LiveClient liveClient, TikTokEvent event) {
            System.out.println(event.getClass().getSimpleName());
        }

    }
}

Methods

A client (LiveClient) object contains the following methods.

Method Name Description
connect Connects to the live stream.
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.
getListenersManager Gets and manage TikTokEventListeners

Events

A TikTokLive object has the following events

Message:

Control:

Custom:



Contributing

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

Description
Java implementation of TikTok-Live-Connector library. Receive live stream events (comments, gifts, etc.) in realtime from TikTok LIVE.
Readme 20 MiB
Languages
Java 99.4%
HTML 0.5%