-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.js
More file actions
39 lines (37 loc) · 978 Bytes
/
api.js
File metadata and controls
39 lines (37 loc) · 978 Bytes
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
import { GetClientId, GetToken } from "./shared.js";
export async function FetchUserInfo() {
try {
const response = await fetch("https://api.twitch.tv/helix/users", {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${GetToken()}`,
"Client-Id": GetClientId(),
},
});
const data = await response.json();
return data.data[0];
} catch (error) {
console.error(error);
}
}
export async function SubscribeTopic(topic) {
try {
const response = await fetch(
"https://api.twitch.tv/helix/eventsub/subscriptions",
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${GetToken()}`,
"Client-Id": GetClientId(),
},
body: JSON.stringify(topic),
}
);
const data = await response.json();
return data;
} catch (error) {
console.error(error);
}
}