[IMPORTANT] SpotifyLocalAPI not working
With the last version, has worked one time, but no more. Play and pause doesn't work.
Also on Example project, once connected to Spotify, doesn't receive Title, Artist, Album. Previous and Skip buttons are working ok. Spotify version 1.0.85.257.gOf8531bd
I can confirm that with the latest Spotify release and the latest API release, Play does not work anymore.
I am also having problems with play or PlayUrl function
I'm having the same issue
same here play, pause etc. doesn't work yesterday i was able to fix it with the solution provided in #253 [Spotify version 1.0.85.257.gOf8531bd]
LocalAPI Seems to broken. GetStatus() reuturns always Null. It hast been down since yesterday evening.
The OAuth key request to "http://open.spotify.com/token" is always returning an invalid token.
Yeah same issue here. Can we get an updated version again? :)
Uhhhh, gimme some minutes here, seems like they disabled the OAuth Token, which maybe means local API is dead. Will report back once I find out more...
Well, it seems like they either disabled the Token generation, or sending a User-Agent with the spotify version is not enough anymore. Independently, there is nothing we can do atm because it's an unofficial API and they can just introduce some secret header field which we could not find in ages.
Also, with their changes to the WebAPI which now also allows managing devices & streaming, it's reasonable that they disabled the local API. It was mainly used for the old web-player which is now completely based on the new WebAPI.
There is not much we can do at the current state...
No... just no. I have this (well had actually) working solution and we're going live tomorrow morning and then I need to be able to control Spotify from a tablet (among other things).
Well, guess I'll have to rebuild it to use the web-api and control the playback that way. Guess I should see it from the bright side. Now atleast I have the entire night to fix it. Had it happened tomorrow I'd be ******.
Thank you for the quick update! (I was hoping someone at Spotify accidentally uploaded a test version of their token generator and would fix it shortly)
Why skip and previous still working?
@StepIg Because they emulate media keys, no spotify api involved
So by using the web api, we can control and play songs on the spotify instance running on a windows machine? (So basically the same thing that the LocalAPI did when we called the play method?)
@JohnnyCrazy Because they emulate media keys, no spotify api involved Is then possible to use same method for play and pause keys?
@StepIg It definitely would be, but it doesn't sound viable anyway considering you can't even request song URIs to play now. It's possible that you could use the Play and Pause media keys solution combined with the web API approach (if it lets you play URIs through it) to control Spotify Desktop client playback.
So my jaw just dropped after spending about 5 hours finding this solution to the problem and actually hearing music go through my headphones when I clicked my program's play button.
Assuming we can no longer use the local API (I hope this is temporary), I've made a new class that implements the same interface as my class that used the SpotifyLocalAPI. This new class uses SpotifyWebAPI.
On initialisation we need to request authentication from the Spotify API. Normally this would be hard or tedious to do, except @JohnnyCrazy has already implemented a way in his SpotifyWebAPI example inside the 'Example' folder in this repository.
This is a small adaptation of his example into an async function that you can basically just copy and paste into your project for initialisation of your new web API class.
// The new using statements...
using SpotifyAPI.Web;
using SpotifyAPI.Web.Auth;
using SpotifyAPI.Web.Enums;
SpotifyWebAPI spotify;
async void ResolveAuth()
{
WebAPIFactory webApiFactory = new WebAPIFactory(
"http://localhost",
8000,
// Spotify API Client ID goes here, you SHOULD get your own at https://developer.spotify.com/dashboard/
// It should be noted, "http://localhost:8000" must be whitelisted in your dashboard after getting your own client key
"26d287105e31491889f3cd293d85bfea",
Scope.UserReadPrivate | Scope.UserReadEmail | Scope.PlaylistReadPrivate | Scope.UserLibraryRead |
Scope.UserReadPrivate | Scope.UserFollowRead | Scope.UserReadBirthdate | Scope.UserTopRead | Scope.PlaylistReadCollaborative |
Scope.UserReadRecentlyPlayed | Scope.UserReadPlaybackState | Scope.UserModifyPlaybackState,
new SpotifyAPI.ProxyConfig());
try
{
spotify = await webApiFactory.GetWebApi();
}
catch (Exception ex)
{
throw;
}
if (spotify == null)
return;
}
Now for when we want to play a song, we have to use the functions in SpotifyWebAPI. Intellisense will be able to show you a good amount of information, but for playing a specific URI, here is an example.
public void Play()
{
// Spotify ResumePlayback has a huge amount of parameters.
// By using "uris: " and defining a new list of strings, we are specifying that we want to give only the
// parameter "uris" input, and nothing else (because all parameters here are optional.)
// the parameter uris is simple, it is a list of song uri's you want to play.
// Offset has to be passed in here (although I pass in its default optional parameter value) as
// the compiler won't be able to differentiate between the two different overloads for the method ResumePlayback.
// For many functions in the web API, they will want 'contexts' and 'device ids'. These are basically all optional
// so adapting these functions to replace your local API is probably doable.
spotify.ResumePlayback(uris: new List<string> { "spotify:track:0cWPe8mPRyLMxxe94eRVzs" }, offset: "");
}
If you read the comments you'll understand that I tried to explain some of the web API's jargon that you may have not read up on because you've relied on the local API for a while, so to follow up on my comments, here is an example of how to PAUSE playback, just to show how easy it is.
public void Pause()
{
spotify.PausePlayback();
}
But intellisense shows you can also pass in a device ID string. Completely optional, as shown in the method's summary.
So what if I want to just resume playback instead of play a new song?
public void Play()
{
// Again, we have to state offset's parameter value so it differentiates between the two overloads of the method.
// Just pass in an empty string, as that is its default optional parameter value.
spotify.ResumePlayback(offset: "");
}
Nice writeup @rollersteaam 👍
2 notes:
spotify = await webApiFactory.GetWebApi();will get you a ready-to-use OAuth token, but sadly it's only valid for 30 minutes, and you cant refresh it. There are some alternatives here- I don't think it's temporary, this would be weird for spotify since they, most of the time, are good at deploying stuff. But let's see 😅
Then, local API is dead like we knew it yesterday?
@rollersteaam I tried PausePlayback() and ResumePlayback() but both gave me error "403 - Not available for the current user" I have Scope.UserReadPlaybackState and Scope.UserModifyPlaybackState.
Edit: Maybe it's because I don't have premium?
And shouldn't the offset for:
spotify.ResumePlayback(offset: "");
be an int and not string?