· 6 months ago · Apr 04, 2025, 12:15 PM
1-- Remplacez par vos informations d'authentification Twitch
2local OAUTH_TOKEN = "Bearer w21nxoray974xbjtvsimbcmtyt8bb6" -- Incluez "Bearer " avant le token
3local CLIENT_ID = "gp762nuuoqcoxypju8c569th9wz7q5"
4
5-- Fonction pour effectuer une requête HTTP GET
6local function httpGet(url, headers)
7 local response = http.get(url, headers)
8 if response then
9 local body = response.readAll()
10 response.close()
11 return body
12 else
13 return nil
14 end
15end
16
17-- Fonction pour récupérer les informations d'une chaîne Twitch
18local function getTwitchChannelInfo(channelName)
19 local url = "https://api.twitch.tv/helix/users?login=" .. channelName
20 local headers = {
21 ["Authorization"] = OAUTH_TOKEN,
22 ["Client-ID"] = CLIENT_ID
23 }
24
25 local response = httpGet(url, headers)
26 if not response then
27 print("Erreur : Impossible de récupérer les informations de la chaîne.")
28 return nil
29 end
30
31 local data = textutils.unserializeJSON(response)
32 if data and data.data and #data.data > 0 then
33 return data.data[1]
34 else
35 print("Erreur : Aucune donnée trouvée pour la chaîne spécifiée.")
36 return nil
37 end
38end
39
40-- Fonction pour récupérer le nombre de followers d'une chaîne Twitch
41local function getTwitchFollowers(channelId)
42 local url = "https://api.twitch.tv/helix/users/follows?to_id=" .. channelId
43 local headers = {
44 ["Authorization"] = OAUTH_TOKEN,
45 ["Client-ID"] = CLIENT_ID
46 }
47
48 local response = httpGet(url, headers)
49 if not response then
50 print("Erreur : Impossible de récupérer les followers.")
51 return nil
52 end
53
54 local data = textutils.unserializeJSON(response)
55 if data and data.total then
56 return data.total
57 else
58 print("Erreur : Impossible de lire le nombre de followers.")
59 return nil
60 end
61end
62
63-- Exemple d'utilisation
64local function main()
65 local channelName = "levraisteeltv" --io.read() -- Remplacez par le nom de la chaîne souhaitée
66
67 local channelInfo = getTwitchChannelInfo(channelName)
68 if channelInfo then
69 print("Nom de la chaîne : " .. channelInfo.display_name)
70
71 -- Récupère et affiche le nombre de followers
72 local followers = getTwitchFollowers(channelInfo.id)
73 if followers then
74 print("Nombre de followers : " .. followers)
75 end
76 end
77end
78
79-- Exécuter le programme
80main()