Beispiel #1
0
        public JsonResult CreateCustomPlaylist(string AccessToken, string UserId, string TrackStringList, string PlaylistName)
        {
            CreatedPlaylist playlist = APICalls.CreateNewPlaylist(AccessToken, UserId, PlaylistName);

            TrackList tracklist = APICalls.GetTracks(AccessToken, TrackStringList);

            string URIString = "";

            foreach (Track t in tracklist.tracks)
            {
                URIString += t.uri + ",";
            }
            URIString = URIString.Trim(',');

            AddSongs added = APICalls.AddSongsToPlaylist(AccessToken, UserId, playlist.id, URIString);

            return(Json(new { PlaylistId = playlist.id, TrackIdList = TrackStringList.Trim(',') }));
        }
        public static CreatedPlaylist CreateNewPlaylist(string AccessToken, string UserId, string PlaylistName)
        {
            var client  = new RestClient("https://api.spotify.com/v1");
            var request = new RestRequest("users/{userid}/playlists", Method.POST);

            request.AddUrlSegment("userid", UserId);
            request.AddHeader("Authorization", string.Format("Bearer {0}", AccessToken));
            //request.AddHeader("Content-type", "application/json");
            request.AddJsonBody(new {
                name    = PlaylistName,
                @public = true
            });

            // execute api call and deserialize the results into the object
            IRestResponse   response = client.Execute(request);
            CreatedPlaylist playlist = new CreatedPlaylist();

            playlist = JsonConvert.DeserializeObject <CreatedPlaylist>(response.Content);

            return(playlist);
        }