hellhound/3p/spotifyClient.ts

20 lines
725 B
TypeScript
Raw Normal View History

2025-02-10 22:48:08 +01:00
const s = new URLSearchParams();
s.append("grant_type", "client_credentials");
const spotify_response = await fetch("https://accounts.spotify.com/api/token", {
headers: {
"Authorization": `Basic ${Buffer.from(process.env.SPOTIFY_CLIENT + ":" + process.env.SPOTIFY_SECRET).toString('base64')}`,
"Content-Type": "application/x-www-form-urlencoded"
},
body: s.toString(),
method: "POST"
}).then(res => res.json());
const sptToken = spotify_response.access_token;
export async function spotifyFetch(url: string): Promise<any> {
return fetch("https://api.spotify.com/v1" + url, {
headers: {
"Authorization": `Bearer ${sptToken}`
}
}).then(res => res.json());
}