Twitch 채팅 참여자(viewer, chatter) 리스트 가져오기 (JavaScript)
Posted 2019. 4. 15. 15:11, Filed under: 개발/JavaScriptTwitch 채팅 참여자 리스트 가져오기
별로 어려운 것은 없으나 코드를 작성할 일이 있어 기록해둔다.
아래의 그림과 같은 트위치 채팅창에서 ≡ 모양 아이콘을 누르면 (참고 - 19년 8월 현재는 사람 모양 아이콘으로 바뀌었다.)
아래의 그림처럼 채팅 참여자 리스트가 나온다. (시청자의 아이디는 직접 *로 처리했으며 실제로는 온전히 다 나온다.)
위와 같은 Twitch 방송의 채팅 참여자 리스트를 얻으려면 아래의 주소로 요청을 하면 된다. client-id 등은 필요 없다.
https://tmi.twitch.tv/group/user/[broadcaster id]/chatters
ajax 호출 예제
jQuery 와 ajax로 호출하는 예제 코드는 아래와 같다. twitchplayspokemon 의 채팅 참여자 리스트를 가져온다.
$.ajax({
url: "https://tmi.twitch.tv/group/user/twitchplayspokemon/chatters",
type: "GET",
dataType:"json",
success: function(data) {
console.log("success", data);
},
error: function(error){
console.log("error", error);
}
});
응답은 아래와 같다. 시청자의 아이디는 직접 *로 처리했으며 실제 요청 시에는 온전히 다 나온다.
{
"_links": {},
"chatter_count": 207,
"chatters": {
"broadcaster": [
"twitchplayspokemon"
],
"vips": [
"tpp***"
],
"moderators": [
"its***",
"tpp***",
"tpp***"
],
"staff": [],
"admins": [],
"global_mods": [],
"viewers": [
"2tsu***",
"aby***",
"ace***",
"ace***",
"apr***",
"arc***",
"asy***" // 이하 생략
]
}
}