Reputation: 25
I have an android app, which should execute some specific commands on an other computer where spotify is running as desktop app.
The current state is, that i have a blank activity with a button. If the button is pressed, my mobile phone with the android app should execute this command from spotify web api:
https://developer.spotify.com/console/put-pause/
the command is like: curl -X "PUT" "https://api.spotify.com/v1/me/player/pause" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
I'm trying out different things and ways to solve that now for the whole day and nothing works. Has anyone a similar problem or some tips how to do it?
Thank you!
Upvotes: 0
Views: 296
Reputation: 1
Please be aware that player pause/play in spotify API is a premium feature.
{
"error" : {
"status" : 403,
"message" : "Player command failed: Premium required",
"reason" : "PREMIUM_REQUIRED"
}
}
Upvotes: 0
Reputation: 557
The mentioned API endpoint does work for me on the web console as well as curl request on my desktop. If this does not work for you, please check if your authorization token does include the scope user-modify-playback-state
.
Regarding tips: The Spotify libraries for authorization and playback control are pretty easy to integrate.
I do not know exactly if the playback control part is only for the playback on your device (mobile phone) or does include your use case to control the playback on your desktop. If not, you could implement this as a simple OkHttp request:
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("https://api.spotify.com/v1/me/player/pause")
.put(null)
.addHeader("Authorization", "Bearer xxxx-xxxx-xxxx…")
.addHeader("Content-Type", "application/json")
.addHeader("Accept", "application/json")
.build();
Response response = client.newCall(request).execute();
If this does not help, it would be good to know some more details from your attempts of calling this api, like the actual call in Java or responses/ errors.
Upvotes: 1