20 lines
780 B
JavaScript
20 lines
780 B
JavaScript
import * as Variables from "./Variables.js";
|
|
|
|
// Uses the API to get the channel ID.
|
|
// Interesting problem: You have to use either an API key or a Auth2.0.
|
|
// I think only developer asses will be using this, so we'll use API keys.
|
|
export async function GetChannelID(APIKey, Channel) {
|
|
if (Channel == "" || APIKey == "") {
|
|
console.error("Forgot a variable.");
|
|
return;
|
|
}
|
|
if (Channel.slice(0, 1) != "@") {
|
|
// Apply the correct Handle
|
|
Channel = "@" + Channel;
|
|
}
|
|
// Get the channel ID
|
|
var webbiesite = "https://www.googleapis.com/youtube/v3/channels";
|
|
var response = await fetch(webbiesite + "?part=id&forHandle=" + Channel + "&key=" + APIKey, {method: "GET"})
|
|
.then((response) => response.json());
|
|
localStorage.setItem(Variables.YoutubeID, response.items[0].id);
|
|
}
|