mirror of
https://github.com/musix-org/musix-oss
synced 2025-07-07 01:20:48 +00:00
Fix code to work on this decade 1/x
This commit is contained in:
28
src/funcs/getSpotifyKey.js
Normal file
28
src/funcs/getSpotifyKey.js
Normal file
@ -0,0 +1,28 @@
|
||||
module.exports = async function (client) {
|
||||
|
||||
const request = require("request");
|
||||
|
||||
const refresh_token = client.config.spotify_refresh_token;
|
||||
const authOptions = {
|
||||
url: "https://accounts.spotify.com/api/token",
|
||||
headers: {
|
||||
Authorization: "Basic " +
|
||||
new Buffer(client.config.spotify_client_id + ":" + client.config.spotify_client_secret).toString("base64"),
|
||||
},
|
||||
form: {
|
||||
grant_type: "refresh_token",
|
||||
refresh_token: refresh_token,
|
||||
},
|
||||
json: true,
|
||||
};
|
||||
|
||||
request.post(authOptions, function (error, response, body) {
|
||||
if (!error && response.statusCode === 200) {
|
||||
client.spotify.setAccessToken(body.access_token);
|
||||
client.config.spotify_access_key = body.access_token
|
||||
if (client.config.devMode) console.log("- Spotify access token set -");
|
||||
} else {
|
||||
console.log("An error occured whilst getting spotify access key");
|
||||
}
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user