TikTok 내부 WebCast 푸시 서비스에 연결하여 TikTok LIVE에서 실시간으로 댓글, 선물 등의 라이브 스트림 이벤트를 받을 수 있는 Node.js 라이브러리입니다. 패키지에는 사용자 이름( uniqueId
)만 사용하여 WebCast 서비스에 연결하는 래퍼가 포함되어 있습니다. 이를 통해 자신의 라이브 채팅은 물론 다른 스트리머의 라이브 채팅에도 연결할 수 있습니다. 자격 증명이 필요하지 않습니다. 채팅 댓글 외에도 회원 가입, 선물, 구독, 시청자, 팔로우, 공유, 질문, 좋아요 및 전투와 같은 기타 이벤트를 추적할 수 있습니다. 세션 ID를 제공하여 채팅에 자동 메시지를 보낼 수도 있습니다.
다른 프로그래밍 언어를 선호하시나요?
참고: 이는 공식 API가 아닙니다. 리버스 엔지니어링 프로젝트입니다.
참고: 이 JavaScript 라이브러리는 Node.js 환경에서 사용하기 위한 것입니다. 브라우저(클라이언트 측)에서 데이터를 처리하거나 표시하려면 Node.js 환경에서 브라우저로 데이터를 전송해야 합니다. 이에 대한 좋은 접근 방식은 Socket.IO 또는 대기 시간이 짧은 다른 통신 프레임워크를 사용하는 것입니다. 전체 예제 프로젝트는 여기에서 찾을 수 있습니다: TikTok-Chat-Reader
업데이트 :
TikTok 측의 변경으로 인해 v1.1.7 이전 버전은 더 이상 작동하지 않습니다. 이러한 버전 중 하나를 사용하는 경우npm i tiktok-live-connector
명령을 사용하여 최신 버전으로 업그레이드하세요.
npm i tiktok-live-connector
const { WebcastPushConnection } = require ( 'tiktok-live-connector' ) ;
// Username of someone who is currently live
let tiktokUsername = "officialgeilegisela" ;
// Create a new wrapper object and pass the username
let tiktokLiveConnection = new WebcastPushConnection ( tiktokUsername ) ;
// Connect to the chat (await can be used as well)
tiktokLiveConnection . connect ( ) . then ( state => {
console . info ( `Connected to roomId ${ state . roomId } ` ) ;
} ) . catch ( err => {
console . error ( 'Failed to connect' , err ) ;
} )
// Define the events that you want to handle
// In this case we listen to chat messages (comments)
tiktokLiveConnection . on ( 'chat' , data => {
console . log ( ` ${ data . uniqueId } (userId: ${ data . userId } ) writes: ${ data . comment } ` ) ;
} )
// And here we receive gifts sent to the streamer
tiktokLiveConnection . on ( 'gift' , data => {
console . log ( ` ${ data . uniqueId } (userId: ${ data . userId } ) sends ${ data . giftId } ` ) ;
} )
// ...and more events described in the documentation below
새로운 WebcastPushConnection
객체를 생성하려면 다음 매개변수가 필요합니다.
WebcastPushConnection(uniqueId, [options])
매개변수 이름 | 필수의 | 설명 |
---|---|---|
고유 ID | 예 | 브로드캐스터의 고유한 사용자 이름입니다. 이 이름은 URL에서 찾을 수 있습니다. 예: https://www.tiktok.com/@officialgeilegisela/live => officialgeilegisela |
옵션 | 아니요 | 여기서는 다음과 같은 선택적 연결 속성을 설정할 수 있습니다. 값을 지정하지 않으면 기본값이 사용됩니다.processInitialData (기본값: true )마지막 초의 오래된 메시지를 포함하는 초기 데이터를 처리할지 정의합니다. fetchRoomInfoOnConnect (기본값: true )connect() 에서 모든 객실 정보를 가져오려는지 정의합니다. 이 옵션을 활성화하면 오프라인 방에 연결되지 않습니다. 활성화되면 연결 결과에 roomInfo 속성을 통한 회의실 정보가 포함됩니다. getRoomInfo() 함수를 사용하여 (연결되지 않은 상태에서도) 수동으로 방 정보를 검색할 수도 있습니다.enableExtendedGiftInfo (기본값: false )선물 이름, 가격, 이미지 등 선물에 대한 자세한 정보를 받고 싶은지 정의하세요. 해당 정보는 선물 이벤트 시 안내해 드립니다. enableWebsocketUpgrade (기본값: true )TikTok이 제공하는 경우 요청 폴링 대신 WebSocket 연결을 사용할지 정의하세요. requestPollingIntervalMs (기본값: 1000 )WebSocket을 사용하지 않는 경우 폴링 간격을 요청합니다. sessionId (기본값: null )sendMessage() 함수를 통해 자동 채팅 메시지를 보내려는 경우 여기에서 TikTok 계정의 현재 세션 ID( sessionid 쿠키 값)를 지정할 수 있습니다. 예시 보기clientParams (기본값: {} )Webcast API에 대한 사용자 정의 클라이언트 매개변수입니다. requestHeaders (기본값: {} )사용자 정의 요청 헤더가 axios에 전달되었습니다. websocketHeaders (기본값: {} )websocket.client에 전달된 사용자 정의 websocket 헤더. requestOptions (기본값: {} )사용자 정의 요청 옵션이 axios에 전달되었습니다. 여기서는 httpsAgent 지정하여 프록시와 timeout 값을 사용할 수 있습니다. 예를 참조하세요.websocketOptions (기본값: {} )websocket.client에 전달된 사용자 정의 websocket 옵션입니다. 여기에서 프록시를 사용하도록 agent 와 timeout 값을 지정할 수 있습니다. 예를 참조하세요.signProviderOptions (기본값: {} )TikTok 서명 서버에 대한 사용자 정의 요청 옵션입니다. 여기에서 host , params 및 headers 지정할 수 있습니다. |
예시 옵션:
let tiktokLiveConnection = new WebcastPushConnection ( tiktokUsername , {
processInitialData : false ,
enableExtendedGiftInfo : true ,
enableWebsocketUpgrade : true ,
requestPollingIntervalMs : 2000 ,
clientParams : {
"app_language" : "en-US" ,
"device_platform" : "web"
} ,
requestHeaders : {
"headerName" : "headerValue"
} ,
websocketHeaders : {
"headerName" : "headerValue"
} ,
requestOptions : {
timeout : 10000
} ,
websocketOptions : {
timeout : 10000
} ,
signProviderOptions : {
host : "https://custom-signing-server.com" ,
params : {
"paramName" : "paramValue"
} ,
headers : {
"headerName" : "headerValue"
}
}
} ) ;
WebcastPushConnection
객체에는 다음 메서드가 포함되어 있습니다.
메소드 이름 | 설명 |
---|---|
연결하다 | 라이브 스트림 채팅에 연결됩니다. 연결이 성공적으로 설정되면 해결될 Promise 반환합니다. |
연결을 끊다 | 연결을 끊습니다. |
getState | 캐시된 방 정보를 포함하여 현재 연결 상태를 가져옵니다(아래 참조). |
방정보 가져오기 | 스트리머 정보, 방 상태 및 통계를 포함하여 TikTok API에서 현재 방 정보를 가져옵니다. API 요청이 완료되면 해결될 Promise 를 반환합니다.참고: 연결되지 않은 경우에도 이 함수를 호출할 수 있습니다. 예 |
사용 가능한 선물을 받으세요 | 선물 이름, 이미지 URL, 다이아몬드 가격 및 기타 다양한 정보를 포함하여 사용 가능한 모든 선물 목록을 가져옵니다. API에서 사용 가능한 모든 선물을 검색하면 해결될 Promise 반환합니다.참고: 연결되지 않은 경우에도 이 함수를 호출할 수 있습니다. 예 |
메시지 보내기(text, [sessionId]) | 제공된 세션 쿠키(생성자 옵션 또는 두 번째 함수 매개변수를 통해 지정)를 사용하여 현재 라이브 룸에 채팅 메시지를 보냅니다. 채팅 메시지가 API에 제출되면 해결될 Promise 반환합니다.경고: 이 기능의 사용에 따른 위험은 사용자 본인이 부담합니다. 스팸 메시지를 보내면 TikTok 계정이 정지될 수 있습니다. 조심하세요! 예 |
WebcastPushConnection
객체에는 .on(eventName, eventHandler)
통해 처리할 수 있는 다음과 같은 이벤트가 있습니다.
제어 이벤트:
메시지 이벤트:
맞춤 이벤트:
connected
연결이 성공적으로 설정되면 트리거됩니다.
tiktokLiveConnection . on ( 'connected' , state => {
console . log ( 'Hurray! Connected!' , state ) ;
} )
{
isConnected : true ,
upgradedToWebsocket : true ,
roomId : '7137682087200557829' ,
roomInfo : {
AnchorABMap : { } ,
admin_user_ids : [ ] ,
anchor_scheduled_time_text : '' ,
anchor_share_text : '' ,
anchor_tab_type : 7 ,
answering_question_content : '' ,
app_id : 1233 ,
audio_mute : 0 ,
auto_cover : 0 ,
book_end_time : 0 ,
book_time : 0 ,
business_live : 0 ,
challenge_info : '' ,
client_version : 250701 ,
comment_has_text_emoji_emote : 0 ,
comment_name_mode : 0 ,
commerce_info : {
commerce_permission : 0 ,
oec_live_enter_room_init_data : '' ,
use_async_load : false
} ,
common_label_list : '' ,
content_tag : '' ,
cover : {
avg_color : '' ,
height : 0 ,
image_type : 0 ,
is_animated : false ,
open_web_url : '' ,
uri : '720x720/tos-maliva-avt-0068/4e64db7f7c37caf9b2df71df8580a9b0' ,
url_list : [ Array ] ,
width : 0
} ,
create_time : 1661871149 ,
deco_list : [ ] ,
deprecated10 : '' ,
deprecated11 : '' ,
deprecated12 : '' ,
deprecated13 : '' ,
deprecated14 : 0 ,
deprecated15 : 0 ,
deprecated16 : 0 ,
deprecated17 : [ ] ,
deprecated18 : 0 ,
deprecated19 : '' ,
deprecated195 : false ,
deprecated2 : '' ,
deprecated20 : 0 ,
deprecated21 : false ,
deprecated22 : 0 ,
deprecated23 : '' ,
deprecated24 : 0 ,
deprecated26 : '' ,
deprecated28 : '' ,
deprecated3 : { } ,
deprecated30 : '' ,
deprecated31 : false ,
deprecated32 : '' ,
deprecated35 : 0 ,
deprecated36 : 0 ,
deprecated39 : '' ,
deprecated4 : 0 ,
deprecated41 : 0 ,
deprecated43 : false ,
deprecated44 : 0 ,
deprecated5 : false ,
deprecated6 : '' ,
deprecated7 : 0 ,
deprecated8 : '' ,
deprecated9 : '' ,
disable_preload_stream : false ,
drawer_tab_position : '' ,
effect_info : [ ] ,
existed_commerce_goods : false ,
fansclub_msg_style : 2 ,
feed_room_label : {
avg_color : '#F1FFEB' ,
height : 0 ,
image_type : 0 ,
is_animated : false ,
open_web_url : '' ,
uri : 'webcast-sg/2ea90002aca1159b5c67' ,
url_list : [ Array ] ,
width : 0
} ,
feed_room_labels : [ ] ,
filter_msg_rules : [ ] ,
finish_reason : 0 ,
finish_time : 1661878842 ,
finish_url : '' ,
finish_url_v2 : '' ,
follow_msg_style : 2 ,
forum_extra_data : '' ,
game_tag : [ ] ,
gift_msg_style : 2 ,
gift_poll_vote_enabled : false ,
group_source : 0 ,
has_commerce_goods : false ,
have_wishlist : false ,
hot_sentence_info : '' ,
id : 7137682087200558000 ,
id_str : '7137682087200557829' ,
indicators : [ ] ,
interaction_question_version : 0 ,
introduction : '' ,
is_gated_room : false ,
is_replay : false ,
is_show_user_card_switch : false ,
last_ping_time : 1661878842 ,
layout : 0 ,
like_count : 0 ,
link_mic : {
audience_id_list : [ ] ,
battle_scores : [ ] ,
battle_settings : [ Object ] ,
channel_id : 0 ,
followed_count : 0 ,
linked_user_list : [ ] ,
multi_live_enum : 1 ,
rival_anchor_id : 0 ,
show_user_list : [ ]
} ,
linker_map : { } ,
linkmic_layout : 0 ,
live_distribution : [ ] ,
live_id : 12 ,
live_reason : '' ,
live_room_mode : 0 ,
live_sub_only : 0 ,
live_type_audio : false ,
live_type_linkmic : false ,
live_type_normal : true ,
live_type_sandbox : false ,
live_type_screenshot : false ,
live_type_social_live : false ,
live_type_third_party : false ,
living_room_attrs : {
admin_flag : 0 ,
rank : 0 ,
room_id : 7137682087200558000 ,
room_id_str : '7137682087200557829' ,
silence_flag : 0
} ,
lottery_finish_time : 0 ,
mosaic_status : 0 ,
os_type : 1 ,
owner : {
allow_find_by_contacts : false ,
allow_others_download_video : false ,
allow_others_download_when_sharing_video : false ,
allow_share_show_profile : false ,
allow_show_in_gossip : false ,
allow_show_my_action : false ,
allow_strange_comment : false ,
allow_unfollower_comment : false ,
allow_use_linkmic : false ,
avatar_large : [ Object ] ,
avatar_medium : [ Object ] ,
avatar_thumb : [ Object ] ,
badge_image_list : [ ] ,
badge_list : [ ] ,
bg_img_url : '' ,
bio_description : 'HH???تابعوني انستغرامnاذا سقطت سأخذ الجميع معيn?Alin_issa22?' ,
block_status : 0 ,
border_list : [ ] ,
comment_restrict : 0 ,
commerce_webcast_config_ids : [ ] ,
constellation : '' ,
create_time : 0 ,
deprecated1 : 0 ,
deprecated12 : 0 ,
deprecated13 : 0 ,
deprecated15 : 0 ,
deprecated16 : false ,
deprecated17 : false ,
deprecated18 : '' ,
deprecated19 : false ,
deprecated2 : 0 ,
deprecated21 : 0 ,
deprecated28 : false ,
deprecated29 : '' ,
deprecated3 : 0 ,
deprecated4 : 0 ,
deprecated5 : '' ,
deprecated6 : 0 ,
deprecated7 : '' ,
deprecated8 : 0 ,
disable_ichat : 0 ,
display_id : 'alin.i7' ,
enable_ichat_img : 0 ,
exp : 0 ,
fan_ticket_count : 0 ,
fold_stranger_chat : false ,
follow_info : [ Object ] ,
follow_status : 0 ,
ichat_restrict_type : 0 ,
id : 6672446849804223000 ,
id_str : '6672446849804223493' ,
is_follower : false ,
is_following : false ,
link_mic_stats : 0 ,
media_badge_image_list : [ ] ,
modify_time : 1661427082 ,
need_profile_guide : false ,
new_real_time_icons : [ ] ,
nickname : '?ALIN?' ,
own_room : [ Object ] ,
pay_grade : [ Object ] ,
pay_score : 0 ,
pay_scores : 0 ,
push_comment_status : false ,
push_digg : false ,
push_follow : false ,
push_friend_action : false ,
push_ichat : false ,
push_status : false ,
push_video_post : false ,
push_video_recommend : false ,
real_time_icons : [ ] ,
sec_uid : 'MS4wLjABAAAAuUKuWAiw0GQO2_zOeyns0YCBRK7ztdoDWAAQ6gPFLBNSdTs-g5BsgScwTD9jWeK_' ,
secret : 0 ,
share_qrcode_uri : '' ,
special_id : '' ,
status : 1 ,
ticket_count : 0 ,
top_fans : [ ] ,
top_vip_no : 0 ,
upcoming_event_list : [ ] ,
user_attr : [ Object ] ,
user_role : 0 ,
verified : false ,
verified_content : '' ,
verified_reason : '' ,
with_car_management_permission : false ,
with_commerce_permission : false ,
with_fusion_shop_entry : false
} ,
owner_device_id : 0 ,
owner_device_id_str : '' ,
owner_user_id : 6672446849804223000 ,
owner_user_id_str : '' ,
pre_enter_time : 0 ,
preview_flow_tag : 0 ,
ranklist_audience_type : 0 ,
relation_tag : '' ,
replay : true ,
room_audit_status : 0 ,
room_auth : {
Banner : 1 ,
BroadcastMessage : 0 ,
Chat : true ,
ChatL2 : false ,
ChatSubOnly : false ,
CommercePermission : 0 ,
CustomizablePoll : 0 ,
Danmaku : false ,
Digg : true ,
DonationSticker : 2 ,
EventPromotion : 0 ,
Gift : true ,
GiftAnchorMt : 1 ,
GiftPoll : 0 ,
GoldenEnvelope : 0 ,
GoldenEnvelopeActivity : 0 ,
InteractionQuestion : true ,
Landscape : 2 ,
LandscapeChat : 0 ,
LuckMoney : true ,
Pictionary : 0 ,
Poll : 0 ,
Promote : false ,
PromoteOther : 0 ,
Props : false ,
PublicScreen : 1 ,
QuickChat : 0 ,
Rank : 0 ,
RoomContributor : false ,
Share : true ,
ShareEffect : 0 ,
ShoppingRanking : 0 ,
UserCard : true ,
UserCount : 0 ,
Viewers : false ,
deprecated1 : false ,
deprecated2 : 0 ,
deprecated3 : 0 ,
deprecated4 : 0 ,
deprecated5 : 0 ,
deprecated6 : 0 ,
deprecated7 : 0 ,
deprecated8 : 0 ,
deprecated9 : 0 ,
transaction_history : 1 ,
use_user_pv : false
} ,
room_create_ab_param : '' ,
room_layout : 0 ,
room_sticker_list : [ ] ,
room_tabs : [ ] ,
room_tag : 0 ,
scroll_config : '' ,
search_id : 0 ,
share_msg_style : 2 ,
share_url : 'https://m.tiktok.com/share/live/7137682087200557829/?language=en' ,
short_title : '' ,
short_touch_items : [ ] ,
social_interaction : { linkmic_scene_linker : { } , multi_live : [ Object ] } ,
start_time : 0 ,
stats : {
deprecated1 : 0 ,
deprecated2 : '' ,
digg_count : 0 ,
enter_count : 0 ,
fan_ticket : 0 ,
follow_count : 686 ,
gift_uv_count :