SHARE
TWEET

Untitled

a guest May 23rd, 2019 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const axios = require("axios");
  2. const spotify = require("./credentials");
  3.  
  4. const getAccessToken = (req, res, next) => {
  5.     const { code } = req.query;
  6.  
  7.     const data = {
  8.         grant_type: "authorization_code",
  9.         code,
  10.         ...spotify
  11.     };
  12.  
  13.     axios({
  14.         url: 'https://accounts.spotify.com/api/token',
  15.         method: 'post',
  16.         params: {
  17.           grant_type: 'client_credentials'
  18.         },
  19.         headers: {
  20.           'Accept':'application/json',
  21.           'Content-Type': 'application/x-www-form-urlencoded'
  22.         },
  23.         auth: {
  24.           username: spotify.client_id,
  25.           password: spotify.client_secret
  26.         }
  27.       }).then(function(response) {
  28.           console.log(response);
  29.       }).catch(function(error) {
  30.           console.log(error)
  31.       });
  32. };
  33.  
  34. module.exports = getAccessToken;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top