-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubscribe.php
More file actions
81 lines (71 loc) · 2.5 KB
/
subscribe.php
File metadata and controls
81 lines (71 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
require_once 'config.php';
// 1. Önce App Access Token (Client Credentials) alıyoruz
$tokenPostData = http_build_query([
'grant_type' => 'client_credentials',
'client_id' => KICK_CLIENT_ID,
'client_secret' => KICK_CLIENT_SECRET
]);
$chToken = curl_init('https://id.kick.com/oauth/token');
curl_setopt($chToken, CURLOPT_RETURNTRANSFER, true);
curl_setopt($chToken, CURLOPT_POST, true);
curl_setopt($chToken, CURLOPT_POSTFIELDS, $tokenPostData);
curl_setopt($chToken, CURLOPT_HTTPHEADER, [
'Content-Type: application/x-www-form-urlencoded'
]);
$tokenResponse = curl_exec($chToken);
$tokenHttpCode = curl_getinfo($chToken, CURLINFO_HTTP_CODE);
curl_close($chToken);
$tokenData = json_decode($tokenResponse, true);
if ($tokenHttpCode !== 200 || !isset($tokenData['access_token'])) {
die("<h1>Hata: App Access Token Alınamadı</h1><pre>" . htmlspecialchars($tokenResponse) . "</pre>");
}
$appAccessToken = $tokenData['access_token'];
// 2. App Access Token ile KICK_BROADCASTER_ID (Senin Kanalın) için Webhook aboneliği başlatıyoruz
$postData = json_encode([
'method' => 'webhook',
'broadcaster_user_id' => (int)KICK_BROADCASTER_ID,
'events' => [
[
'name' => 'chat.message.sent',
'version' => 1
],
[
'name' => 'channel.followed',
'version' => 1
],
[
'name' => 'channel.subscription.new',
'version' => 1
],
[
'name' => 'channel.subscription.gifts',
'version' => 1
],
[
'name' => 'livestream.status.updated',
'version' => 1
]
]
]);
$ch = curl_init('https://api.kick.com/public/v1/events/subscriptions');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer ' . $appAccessToken
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "<h1>Webhook Abonelik Sonucu (Ana Kanal İçin)</h1>";
if ($httpCode === 200) {
echo "<p style='color:green;'>Başarılı! Artık (" . KICK_BROADCASTER_ID . ") ID'li kanaldaki mesajlar webhook.php dosyasına gelecek.</p>";
} else {
echo "<p style='color:red;'>Hata ($httpCode):</p>";
}
echo "<pre>" . htmlspecialchars($response) . "</pre>";
echo "<br><a href='index.php'>Dashboard'a Dön</a>";
?>