Advertisement
b3gund4L

Api Spotify

Apr 11th, 2017
40,867
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 1.17 KB | None | 0 0
  1. curl -X GET "https://api.spotify.com/v1/users/***userId***/playlists" -H "Accept: application/json" -H "Authorization: Bearer ***ACCESSTOKEN***"
  2.    
  3. app.get('/user-playlists', function(req, res){
  4.  
  5.     var options = {
  6.         url: 'https://api.spotify.com/v1/me',
  7.         headers: {
  8.             'Authorization': 'Bearer ' + access_token
  9.         },
  10.         json: true
  11.     };
  12.  
  13.     rp(options).then(function(body) {
  14.         userEmail = body.email;
  15.         userId = body.id;
  16.  
  17.         var optionsTwo = {
  18.             url: 'https://api.spotify.com/v1/users/' + userId + '/playlists',
  19.             headers: {
  20.                 'Authorization': 'Bearer ' + access_token
  21.             },
  22.             json: true
  23.         };
  24.  
  25.         return rp(optionsTwo).then(function (body) {
  26.             playlists = body.items;
  27.             console.log(playlists)
  28.             res.json(playlists);
  29.         });
  30.     }).catch(function (err) {
  31.         console.log(err)
  32.     })
  33. });
  34.    
  35. $.ajax({
  36.    type: 'GET',
  37.    url: 'http://localhost:3000/user-playlists',
  38.    contentType: 'application/json',
  39.    success: function(data) {
  40.      console.log(data); //this is only returning four playlist items
  41.    }
  42.  });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement