New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve User's Currently Playing Track #12

Closed
jsanders67 opened this Issue Mar 22, 2015 · 297 comments

Comments

Projects
None yet
@jsanders67

jsanders67 commented Mar 22, 2015

Is there a way/plans of an update to the web-api that provides a way to get the song a user is currently listening to?

@thelinmichael

This comment has been minimized.

Contributor

thelinmichael commented Mar 23, 2015

Thanks for opening this issue @jsanders67. Without going into detail - yes, we'd like to expose this in the Web API. How and when is uncertain and I urge you not to expect this feature being available in the short term.

@sean1rose

This comment has been minimized.

sean1rose commented Apr 1, 2015

Looking forward to this being implemented as well!

@vivekvasani

This comment has been minimized.

vivekvasani commented Apr 20, 2015

+1 for this enhancement

@DefV

This comment has been minimized.

DefV commented Apr 23, 2015

+1

@rjrahul

This comment has been minimized.

rjrahul commented Apr 27, 2015

+1. Looking for a way to get list of tracks played by user in reverse chronological order.

@ardixiv

This comment has been minimized.

ardixiv commented May 25, 2015

+1

@ghost

This comment has been minimized.

ghost commented May 26, 2015

+1

3 similar comments
@luxcapto

This comment has been minimized.

luxcapto commented May 28, 2015

+1

@Eastborn

This comment has been minimized.

Eastborn commented Jun 5, 2015

+1

@antons-

This comment has been minimized.

antons- commented Jun 24, 2015

+1

@jsanders67

This comment has been minimized.

jsanders67 commented Jun 24, 2015

I know this is not an ideal workaround, but I thought I would post it anyways. If you get your user to subscribe to last.fm or if they already are, you can use the last.fm api to get their current song they are listening to on spotify. Obviously this is annoying to make them subscribe to last.fm with their spotify account, but it's the only way I have found with spotify's current api setup to get the current song being played by the user

@SkylerLutz

This comment has been minimized.

SkylerLutz commented Jun 29, 2015

+1

10 similar comments
@emanuelemacri

This comment has been minimized.

emanuelemacri commented Jul 2, 2015

+1

@AuroraAri

This comment has been minimized.

AuroraAri commented Jul 11, 2015

+1

@BrandonSlaght

This comment has been minimized.

BrandonSlaght commented Jul 12, 2015

+1

@linath

This comment has been minimized.

linath commented Jul 14, 2015

+1

@thomasvamos

This comment has been minimized.

thomasvamos commented Jul 14, 2015

+1

@kaulbersch

This comment has been minimized.

kaulbersch commented Jul 14, 2015

+1

@b0tting

This comment has been minimized.

b0tting commented Jul 14, 2015

+1

@Vultour

This comment has been minimized.

Vultour commented Jul 14, 2015

+1

@jolantz

This comment has been minimized.

jolantz commented Jul 15, 2015

+1

@OGPoyraz

This comment has been minimized.

OGPoyraz commented Jul 15, 2015

+1

@antons-

This comment has been minimized.

antons- commented Jul 15, 2015

Hey @thelinmichael is there any updates on this? There is clearly alot of interest for this feature :)

@wenzowski

This comment has been minimized.

wenzowski commented Jul 15, 2015

👍 this was easy with the old api.

@thelinmichael

This comment has been minimized.

Contributor

thelinmichael commented Jul 16, 2015

Sorry @antons-, no updates yet.

@wenzowski, just to clarify for others, I assume the old API you're referring to is not the deprecated Metadata Web API, but the Apps API for applications integrated in Spotify's desktop application.

@wenzowski

This comment has been minimized.

wenzowski commented Jul 17, 2015

@thelinmichael yes, was referring to apps api

@srijak

This comment has been minimized.

srijak commented Aug 4, 2015

+1

@jpiepkow

This comment has been minimized.

jpiepkow commented Apr 1, 2017

@mcoalson could you not just use the oauth flow for the user your trying to controlling playback for and use there token for the /me routes?

@kvanzuijlen

This comment has been minimized.

kvanzuijlen commented Apr 3, 2017

@hycday It wasn't refreshing for me either. However, it worked after I changed my playback device from my laptop to my phone (using my phone) and back (using my laptop). I did this a couple of times (after the first time it was stuck again when the song was finished) and now it's fully functional (even when playing from my laptop).

@kvanzuijlen

This comment has been minimized.

kvanzuijlen commented Apr 3, 2017

Somehow the current track endpoint only works when Spotify is running on my mobile phone (the song can be played from my laptop though). Indeed, it's still in beta ;). Love how easy (and well (if Spotify is running on my phone)) it works though.

@jpiepkow

This comment has been minimized.

jpiepkow commented Apr 3, 2017

For anyone running into issues with getting the correct current track. I was doing a little testing yesterday and for me the workaround at the moment was the following.

Get devices => call play endpoint with current active device => get current track.

Doing this always retrieves the most up to date and current information. This is very hackish and is not a long term solution but for my app will do fine until the current track endpoint works more consistently.

TLDR: all the new beta endpoints that control playback seem to "refresh" the current track information for a user.

@gabernardone

This comment has been minimized.

gabernardone commented Apr 3, 2017

Why am I getting "Access Denied"?
I tried Spotify's own WebAPI Console and nothing.

{ "error": { "status": 401, "message": "Permissions missing" } }

@jpiepkow

This comment has been minimized.

jpiepkow commented Apr 3, 2017

The access token must have the user-read-currently-playing and/or user-read-playback-state scope authorized in order to read information.

That should fix your Permissions missing issue @gabernardone

@gabernardone

This comment has been minimized.

gabernardone commented Apr 3, 2017

@jpiepkow Strange, because I'm adding all the scopes.
image

image

@jpiepkow

This comment has been minimized.

jpiepkow commented Apr 3, 2017

user-read-currently-playing is the scope I use for this endpoint and it works correct for me.
@gabernardone

I believe user-read-recently-played is for the recently played endpoint. Whatever you are using to request an oAuth may not have the new scopes for the beta endpoints yet.

@gabernardone

This comment has been minimized.

gabernardone commented Apr 3, 2017

@jpiepkow I'm testing with a non-Premium user, would that be it?

@jpiepkow

This comment has been minimized.

jpiepkow commented Apr 3, 2017

@gabernardone it is my understanding that these endpoints only work with premium users

@hughrawlinson

This comment has been minimized.

Member

hughrawlinson commented Apr 4, 2017

@gabernardone hey - this was a problem on our end. The 'user-read-recently-played' scope is incorrect for the 'currently-playing' endpoint. As @jpiepkow noted, the 'user-read-currently-playing' scope is required for that endpoint. I've updated the console now to correct the scope for that endpoint. There's no restriction to premium users for reading the currently playing track, but only premium users can use the endpoints for modifying playback state.

Hope that helps clarify things!

@gabernardone

This comment has been minimized.

gabernardone commented Apr 4, 2017

@hughrawlinson I found it strange even the scope 'user-read-recently-played', glad that it has already been fixed.
I tried again and returned error 400 - "Invalid Id". My user is not premium, would that be the reason?

@hughrawlinson

This comment has been minimized.

Member

hughrawlinson commented Apr 5, 2017

@gabernadone this is on the 'currently-playing' endpoint? That endpoint should work for non-premium users. Could you send me your Spotify username so I can reproduce the issue and pass it on to the team?

@gabernardone

This comment has been minimized.

gabernardone commented Apr 5, 2017

@hughrawlinson Of Course, my user id is 12160188079

@NicolasHaeffner

This comment has been minimized.

NicolasHaeffner commented Apr 10, 2017

The new endpoint is awesome!
Would it be possible to get the current queue?
I am planning to write a kodi plugin to control a connected device and getting the next songs in line would be a great feature

@hughrawlinson

This comment has been minimized.

Member

hughrawlinson commented Apr 10, 2017

Hi @Halbstark - It's not possible right now, but issue #462 is a feature request for the queue endpoint. I'd suggest adding your voice to that ticket 😄

@JMPerez

This comment has been minimized.

Member

JMPerez commented Apr 18, 2017

It would be great to have a websocket/long polling version of the endpoints to get the currently playing track so there is no need to poll every few seconds. This would be useful to build visualisers that need to be in sync with what the user is playing. See these examples.

Let me know if that is a useful feature request so I create its own issue.

Fewer requests also mean it is less likely for the integrations to reach the rate limit and it also means less network overhead both for the user and Spotify.

@mcoalson

This comment has been minimized.

mcoalson commented Apr 25, 2017

Has anyone actually gotten this to work without the "Get devices => call play endpoint with current active device => get current track." hack? I'm getting stuff I played a couple hours ago, but nothing current.

@Serdiev

This comment has been minimized.

Serdiev commented Apr 25, 2017

I've been using it for the last past weeks.

I'm just going to post some code so you can see how it's used. Beware, this code is like a 2 hour hack which is ugly as fuck and just runs on my raspberry pi.

This is my ajax call to it.
$.ajax({ url: "https://api.spotify.com/v1/me/player/currently-playing", type: "GET", dataType: 'json', beforeSend: function(xhr){ xhr.setRequestHeader('Authorization', 'Authorization: Bearer '+bearer);}, success: function(dataload) { Here it works. } });

This is the python script I use for getting the bearer. I'm using the spotipy library for retrieving the bearer code which is used for the ajax call. (This needs to be refreshed every 3600 seconds I believe). I have a really ugly hack which puts the code in an file which I then can read for usage later on in the website. There is most likely a MUCH better way of doing this but I just wanted it to get to work quickly.

import sys
import spotipy
import spotipy.util as util
import time

id = 'Your spotify ID'
secret = 'Your spotify Secret'
url = 'I just put some bullshit url here' #not actually using it for any redirection
scope = 'user-read-currently-playing'

if len(sys.argv) > 1:
    username = sys.argv[1]
else:
    print "Usage: %s username" % (sys.argv[0],)
    sys.exit()

def main_loop():
    while(True):
      get_new_token()
      time.sleep(1000) 
    
def get_new_token():
    token = util.prompt_for_user_token(username, scope, client_id=id,client_secret=secret,redirect_uri=url)
    print("Token",token)
    file = open("token.txt","w")
    file.write(token)
    file.close()
   
main_loop()

Hope that helps!

@asmitter

This comment has been minimized.

Member

asmitter commented Apr 25, 2017

@mcoalson @Serdiev
While we work on a wider fix, we have an open ticket here where you can report your Spotify username and we'll apply a fix for your user.

@unRob

This comment has been minimized.

unRob commented Apr 26, 2017

@JMPerez While not ideal, having every client post activity to Facebook, and then responding their real-time calls has worked somewhat reliably for me for the past couple of years now. If you were to implement a simpler solution, I'd be happy to test it!

@JMPerez

This comment has been minimized.

Member

JMPerez commented Apr 28, 2017

@unRob for now I'm polling every coupe of seconds until there is a better alternative. See https://github.com/jmperez/spotify-player for more details.

@unRob

This comment has been minimized.

unRob commented Apr 28, 2017

@JMPerez Oh, that's cool! I do have a working implementation that doesn't do polling, but my point was more towards signing up for:

Let me know if that is a useful feature request so I create its own issue.

@emilbruckner

This comment has been minimized.

emilbruckner commented May 25, 2017

@JMPerez In my opinion, what you're asking for is what this endpoint should be good for afterall

@sean1rose

This comment has been minimized.

sean1rose commented Jun 16, 2017

+1 for the ability to see what other users are playing now

@duikb00t

This comment has been minimized.

duikb00t commented Jun 19, 2017

+1

1 similar comment
@chvaca

This comment has been minimized.

chvaca commented Jul 19, 2017

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment