❤️❤️?连接到Tiktok Live 3行?❤️❤️
一个受Tiktoklive和Tiktoklivesharp启发的Java库。使用它通过连接到Tiktok的内部网络广播推送服务来接收来自Tiktok Live的实时评论和礼物等实时信息。该库包含一个包装器,该包装器仅使用用户名( uniqueId )连接到网络广播服务。这使您可以连接到自己的实时聊天以及其他流媒体的实时聊天。不需要凭据。可以跟踪成员加入,礼物,订阅,观众,关注者,分享,问题,喜欢和战斗等活动。
加入支持不和谐,并访问#java-support频道以获取问题,贡献和想法。随意提出带有缺失/新功能,修复等的拉动请求等
您喜欢其他编程语言吗?
注意:这不是官方API。这是一个反向工程项目。
小牛
< 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 >1.8.13-Release</ version >
< scope >compile</ scope >
</ dependency >
</ dependencies >gradle
dependencyResolutionManagement {
repositoriesMode . set( RepositoriesMode . FAIL_ON_PROJECT_REPOS )
repositories {
mavenCentral()
maven { url ' https://jitpack.io ' }
}
}
dependencies {
implementation ' com.github.jwdeveloper.TikTok-Live-Java:Client:1.8.13-Release '
} TikTokLive . newClient ( "bangbetmenygy" )
. onGift (( liveClient , event ) ->
{
String message = switch ( event . getGift ()) {
case ROSE -> "ROSE!" ;
case GG -> "GOOD GAME" ;
case TIKTOK -> "Ye" ;
case CORGI -> "Nice gift" ;
default -> "Thank you for " + event . getGift (). getName ();
};
System . out . println ( event . getUser (). getProfileName () + " sends " + message );
})
. onGiftCombo (( liveClient , event ) ->
{
System . out . println ( event . getComboState ()+ " " + event . getCombo () + " " + event . getGift (). getName ());
})
. onRoomInfo (( liveClient , event ) ->
{
var roomInfo = event . getRoomInfo ();
System . out . println ( "Room Id: " + roomInfo . getRoomId ());
System . out . println ( "Likes: " + roomInfo . getLikesCount ());
System . out . println ( "Viewers: " + roomInfo . getViewersCount ());
})
. onJoin (( liveClient , event ) ->
{
System . out . println ( event . getUser (). getProfileName () + "Hello on my stream! " );
})
. onConnected (( liveClient , event ) ->
{
System . out . println ( "Connected to live " );
})
. onError (( liveClient , event ) ->
{
System . out . println ( "Error! " + event . getException (). getMessage ());
})
. buildAndConnect (); TikTokLive . newClient ( "bangbetmenygy" )
. configure (( settings ) ->
{
settings . setHostName ( "bangbetmenygy" ); // This method is useful in case you want change hostname later
settings . setClientLanguage ( "en" ); // Language
settings . setTimeout ( Duration . ofSeconds ( 2 )); // Connection timeout
settings . setLogLevel ( Level . ALL ); // Log level
settings . setPrintToConsole ( true ); // Printing all logs to console even if log level is Level.OFF
settings . setRetryOnConnectionFailure ( true ); // Reconnecting if TikTok user is offline
settings . 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
settings . setSessionId ( "86c3c8bf4b17ebb2d74bb7fa66fd0000" );
//Optional:
//RoomId can be used as an override if you're having issues with HostId.
//You can find it in the HTML for the livestream-page
settings . setRoomId ( "XXXXXXXXXXXXXXXXX" );
})
. buildAndConnect ();
// 控制:
信息:
调试:
TikTokLive . newClient ( "host-name" )
. onReconnecting (( liveClient , event ) ->
{
})
. buildAndConnect ();一般错误事件。您应该处理这个。
TikTokLive . newClient ( "host-name" )
. onError (( liveClient , event ) ->
{
})
. buildAndConnect ();成功建立连接时触发。
TikTokLive . newClient ( "host-name" )
. onConnected (( liveClient , event ) ->
{
})
. buildAndConnect ();连接断开连接时触发。在这种情况下,您可以再次调用Connect()以重新连接逻辑。请注意,您应该等待一点,然后再尝试重新连接以避免被限制。
TikTokLive . newClient ( "host-name" )
. onDisconnected (( liveClient , event ) ->
{
})
. buildAndConnect ();所有活动的基础课
TikTokLive . newClient ( "host-name" )
. onEvent (( liveClient , event ) ->
{
})
. buildAndConnect ();所有活动的基础课
TikTokLive . newClient ( "host-name" )
. onEvent (( liveClient , event ) ->
{
})
. buildAndConnect ();每次出现新的聊天评论时都会触发。
TikTokLive . newClient ( "host-name" )
. onComment (( liveClient , event ) ->
{
})
. buildAndConnect ();当LiverooMinfo更新时,触发了,例如Likes,Giewers,排名...
TikTokLive . newClient ( "host-name" )
. onRoomInfo (( liveClient , event ) ->
{
})
. buildAndConnect ();当用户发送没有组合的礼物(大部分昂贵的礼物)或组合完成时触发
TikTokLive . newClient ( "host-name" )
. onGift (( liveClient , event ) ->
{
})
. buildAndConnect ();当用户创建订阅时,触发。
TikTokLive . newClient ( "host-name" )
. onSubscribe (( liveClient , event ) ->
{
})
. buildAndConnect ();当用户关注流媒体时,触发。基于社交活动。
TikTokLive . newClient ( "host-name" )
. onFollow (( liveClient , event ) ->
{
})
. buildAndConnect ();每次发送礼物时都会触发
@See GiftSendType它有3个州
示例用户与组合发送礼物时
>组合:1-> combostate = giftSendType.begin
组合:4-> combostate = giftSendType.Active
组合:8-> combostate = giftSendType.Active
组合:12-> combostate = giftSendType。
请记住,如果结合材料完成
TikTokLive . newClient ( "host-name" )
. onGiftCombo (( liveClient , event ) ->
{
})
. buildAndConnect ();当实时流由主机终止时触发。还将触发tiktokdisconnectedEvent事件。
TikTokLive . newClient ( "host-name" )
. onLiveEnded (( liveClient , event ) ->
{
})
. buildAndConnect ();每当有人通过问题功能问一个新问题时,都会触发。
TikTokLive . newClient ( "host-name" )
. onQuestion (( liveClient , event ) ->
{
})
. buildAndConnect ();当用户共享流时触发。基于社交活动。
TikTokLive . newClient ( "host-name" )
. onShare (( liveClient , event ) ->
{
})
. buildAndConnect (); TikTokLive . newClient ( "host-name" )
. onLiveUnpaused (( liveClient , event ) ->
{
})
. buildAndConnect ();每当订户发送emote(贴纸)时,都会触发。
TikTokLive . newClient ( "host-name" )
. onEmote (( liveClient , event ) ->
{
})
. buildAndConnect (); TikTokLive . newClient ( "host-name" )
. onJoin (( liveClient , event ) ->
{
})
. buildAndConnect ();当观众发送喜欢的流媒体时,触发。对于有许多观众的流,此事件并不总是由Tiktok触发。
TikTokLive . newClient ( "host-name" )
. onLike (( liveClient , event ) ->
{
})
. buildAndConnect (); TikTokLive . newClient ( "host-name" )
. onLivePaused (( liveClient , event ) ->
{
})
. buildAndConnect (); TikTokLive . newClient ( "host-name" )
. onWebsocketResponse (( liveClient , event ) ->
{
})
. buildAndConnect ();每当Protobuf编码的网络广播消息到达时,都会触发。根据用例,您可以对二进制对象进行验证。
TikTokLive . newClient ( "host-name" )
. onWebsocketUnhandledMessage (( liveClient , event ) ->
{
})
. buildAndConnect (); TikTokLive . newClient ( "host-name" )
. onHttpResponse (( liveClient , event ) ->
{
})
. buildAndConnect ();每当Tiktok发送数据时,都会触发。数据输入为Protobuf消息。根据用例,您可以对二进制对象进行验证。
TikTokLive . newClient ( "host-name" )
. onWebsocketMessage (( liveClient , event ) ->
{
})
. buildAndConnect ();将节省时间的tiktoklivejava的扩展名列表
/**
*
* Listeners are an alternative way of handling events.
* I would to suggest to use then when logic of handing event
* is more complex
*
*/
public static void main ( String [] args ) throws IOException {
showLogo ();
CustomListener customListener = new CustomListener ();
TikTokLive . newClient ( SimpleExample . TIKTOK_HOSTNAME )
. addListener ( customListener )
. buildAndConnect ();
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 {
@ TikTokEventObserver
public void onLike ( LiveClient liveClient , TikTokLikeEvent event ) {
System . out . println ( event . toString ());
}
@ TikTokEventObserver
public void onError ( LiveClient liveClient , TikTokErrorEvent event ) {
// event.getException().printStackTrace();
}
@ TikTokEventObserver
public void onComment ( LiveClient liveClient , TikTokCommentEvent event ) {
var userName = event . getUser (). getName ();
var text = event . getText ();
liveClient . getLogger (). info ( userName + ": " + text );
}
@ TikTokEventObserver
public void onGift ( LiveClient liveClient , TikTokGiftEvent event ) {
var message = switch ( event . getGift ()) {
case ROSE -> "Thanks :)" ;
case APPETIZERS -> ":OO" ;
case APRIL -> ":D" ;
case TIKTOK -> ":P" ;
case CAP -> ":F" ;
default -> ":I" ;
};
liveClient . getLogger (). info ( message );
}
@ TikTokEventHandler
public void onAnyEvent ( LiveClient liveClient , TikTokEvent event ) {
liveClient . getLogger (). info ( event . getClass (). getSimpleName ());
}
}
// 贡献者的图书馆文档
欢迎您的改进!随时打开问题或拉出请求。