//public async Task<AuthenticationToken> GetAccessToken() //{ // RoclappData data = DataAccess.GetRocolappData(); // SpotifyWebAPI.Authentication.ClientId = data.ClientId; // SpotifyWebAPI.Authentication.ClientSecret = data.ClientSecret ; // SpotifyWebAPI.Authentication.RedirectUri = data.RedirectUri; // // before you can access an authenticated method, you'll need to retrieve an access token // // this token must be passed to each method that requires authentication // // also, im storing this in the view state so i can retrieve it again later // AuthenticationToken authenticationToken = await SpotifyWebAPI.Authentication.GetAccessToken(data.Code); // return authenticationToken; //} public async void GetAccessToken() { RoclappData data = DataAccess.GetRocolappData(); //var auth = new ClientCredentialsAuth() //{ // //Your client Id // ClientId = data.ClientId, // //Your client secret UNSECURE!! // ClientSecret = data.ClientSecret, // //How many permissions we need? // Scope = Scope.UserReadPrivate, //}; //Token token = auth.DoAuth(); var spotify = new SpotifyWebAPI() { TokenType = "Bearer", AccessToken = "BQAhqScodO_NRSiu1V4S8eeeEuLZK-Y8CWahzAQ9GmuS14K6wATxn_jTjCgmMF62BJ9vOXnpkmp2aVwxJ5FJ-w", UseAuth = true }; FullTrack track = spotify.GetTrack("3Hvu1pq89D4R0lyPBoujSv"); }
public ActionResult GotoSpotify() { RoclappData data = DataAccess.GetRocolappData(); Uri urlAuthorization = new Uri("https://accounts.spotify.com/authorize/?" + "client_id=" + data.ClientId + "&response_type=code" + "&redirect_uri=" + data.RedirectUri + "&scope=" + data.Scope ); return(Redirect(urlAuthorization.ToString())); }
public static RoclappData GetRocolappData() { RoclappData rd = new RoclappData(); rd.ClientId = "6a5c69fc50be4f11996e54d18ce95843"; rd.ClientSecret = "60822879f8a64ccca934974909daa0bd"; //rd.RedirectUri = "http://138.36.238.199/MainPage/Main";//"http://localhost/Rocolapp/MainPage/Main";//"http://www.google.com.ar"; rd.RedirectUri = "http://localhost/Rocolapp/MainPage/Main"; rd.UserId = "gaston.spotfy"; rd.MainPlaylist = "7Ckc7mWQuXizALdqeJAjWw"; //rd.Scope = "playlist-modify-public&scope=playlist-modify-private&scope=playlist-read-private&scope=playlist-read-collaborative&scope=user-library-read&scope=user-library-modify&scope=user-read-private&scope=user-read-birthdate&scope=user-read-email&scope=user-follow-read&scope=user-follow-modify&scope=user-top-read&scope=user-read-playback-state&scope=user-read-recently-played&scope=user-read-currently-playing&scope=user-modify-playback-state"; rd.Scope = "playlist-read-private playlist-read-collaborative playlist-modify-public playlist-modify-private user-library-read user-library-modify user-read-private user-read-birthdate user-read-email user-follow-read user-follow-modify user-top-read user-read-playback-state user-read-recently-played user-read-currently-playing user-modify-playback-state"; return(rd); }
private PrivateProfile GetUserProfile(string token) { RoclappData data = DataAccess.GetRocolappData(); var spotify = new SpotifyWebAPI() { TokenType = "Bearer", AccessToken = token, UseAuth = true }; PrivateProfile privateProfile = spotify.GetPrivateProfile(); return(privateProfile); }
private PlaybackContext GetCurrentPlayBack(string token) { RoclappData data = DataAccess.GetRocolappData(); var spotify = new SpotifyWebAPI() { TokenType = "Bearer", AccessToken = token, UseAuth = true }; PlaybackContext context = spotify.GetPlayingTrack(); return(context); }
public async void AddTrack() { string trackUri = "1ri6UZpjPLmTCswIXZ6Uq1"; RoclappData data = DataAccess.GetRocolappData(); var spotify = new SpotifyWebAPI() { TokenType = "Bearer", AccessToken = "BQDHN3zZDp36gkpGfuWlyJyxdBYkWDSmTNobRvL_eGFMA-0mUWhhThFXioKJwMfOGaCO3xmnwUOoatL5RfOd29zNex3LFVq2cad01NfdK93TWlVTX9PpM3m9U6mdvQwltMdtIYNmHd4KTENqotEyBLE2wX8SQxrycx1z7lFRy52V9PagVECMgq-m8CA5d2FQcN1QFrc6YxALvG-nqGe4VjrScTBVVl8", UseAuth = true }; string trackPrefix = "spotify:track:"; ErrorResponse response = spotify.AddPlaylistTrack(data.UserId, data.MainPlaylist, trackPrefix + trackUri); }
public async Task <SearchItem> SearchTrack(string query, string tk) { RoclappData data = DataAccess.GetRocolappData(); RocolappUser user = GetUserbyRocolappId(tk); var spotify = new SpotifyWebAPI() { TokenType = "Bearer", AccessToken = user.Token, UseAuth = true }; SearchItem searchItem = spotify.SearchItems(query, SearchType.Track); if (searchItem.Error != null && searchItem.Error.Status == 401) { AutorizationCodeAuth auth = new AutorizationCodeAuth(); //Datos de mi aplicacion Rocolapp auth.ClientId = DataAccess.GetRocolappData().ClientId; auth.RedirectUri = DataAccess.GetRocolappData().RedirectUri; string clientSecret = DataAccess.GetRocolappData().ClientSecret; Token token = auth.RefreshToken(user.RefreshToken, DataAccess.GetRocolappData().ClientSecret); UpdateToken(user.Id.ToString(), token.AccessToken); var withRefreshedToken = new SpotifyWebAPI() { TokenType = "Bearer", AccessToken = token.AccessToken, UseAuth = true }; searchItem = withRefreshedToken.SearchItems(query, SearchType.Track); } return(searchItem); }
public void AddTrackToPlayList([FromBody] Track track) { RoclappData data = DataAccess.GetRocolappData(); string token; RocolappUser user = GetUserbyRocolappId(track.Token); token = user.Token; var spotify = new SpotifyWebAPI() { TokenType = "Bearer", AccessToken = user.Token, UseAuth = true, }; //Agregar la posibilidad de que se aparezca la letra de la cancion string trackPrefix = "spotify:track:"; ErrorResponse response = spotify.AddPlaylistTrack(user.SpotifyId, user.PlaylistId, trackPrefix + track.TrackId); if (response.HasError() && response.Error.Status == 401) { AutorizationCodeAuth auth = new AutorizationCodeAuth(); //Datos de mi aplicacion Rocolapp auth.ClientId = DataAccess.GetRocolappData().ClientId; auth.RedirectUri = DataAccess.GetRocolappData().RedirectUri; string clientSecret = DataAccess.GetRocolappData().ClientSecret; Token newToken = auth.RefreshToken(user.RefreshToken, DataAccess.GetRocolappData().ClientSecret); UpdateToken(user.Id.ToString(), newToken.AccessToken); token = newToken.AccessToken; var withRefreshedToken = new SpotifyWebAPI() { TokenType = "Bearer", AccessToken = newToken.AccessToken, UseAuth = true }; response = withRefreshedToken.AddPlaylistTrack(user.SpotifyId, user.PlaylistId, trackPrefix + track.TrackId); } PlaybackContext context = GetCurrentPlayBack(token); if (context != null && !context.IsPlaying) { try { ResumePlayback(token); } catch (Exception) { throw; } } }