Skip to content
This repository has been archived by the owner. It is now read-only.

Retrieve User's Currently Playing Track #12

Closed
sanjams2 opened this issue Mar 22, 2015 · 297 comments
Closed

Retrieve User's Currently Playing Track #12

sanjams2 opened this issue Mar 22, 2015 · 297 comments

Comments

@sanjams2
Copy link

@sanjams2 sanjams2 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
Copy link
Contributor

@thelinmichael 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
Copy link

@sean1rose sean1rose commented Apr 1, 2015

Looking forward to this being implemented as well!

@vivekvasani
Copy link

@vivekvasani vivekvasani commented Apr 20, 2015

+1 for this enhancement

@DefV
Copy link

@DefV DefV commented Apr 23, 2015

+1

@rjrahul
Copy link

@rjrahul rjrahul commented Apr 27, 2015

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

@ardixiv
Copy link

@ardixiv ardixiv commented May 25, 2015

+1

@ghost
Copy link

@ghost ghost commented May 26, 2015

+1

3 similar comments
@luxcapto
Copy link

@luxcapto luxcapto commented May 28, 2015

+1

@Eastborn
Copy link

@Eastborn Eastborn commented Jun 5, 2015

+1

@antons-
Copy link

@antons- antons- commented Jun 24, 2015

+1

@sanjams2
Copy link
Author

@sanjams2 sanjams2 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
Copy link

@SkylerLutz SkylerLutz commented Jun 29, 2015

+1

10 similar comments
@emanuelemacri
Copy link

@emanuelemacri emanuelemacri commented Jul 2, 2015

+1

@AuroraAri
Copy link

@AuroraAri AuroraAri commented Jul 11, 2015

+1

@BrandonSlaght
Copy link

@BrandonSlaght BrandonSlaght commented Jul 12, 2015

+1

@linath
Copy link

@linath linath commented Jul 14, 2015

+1

@thomasvamos
Copy link

@thomasvamos thomasvamos commented Jul 14, 2015

+1

@kaulbersch
Copy link

@kaulbersch kaulbersch commented Jul 14, 2015

+1

@b0tting
Copy link

@b0tting b0tting commented Jul 14, 2015

+1

@Vultour
Copy link

@Vultour Vultour commented Jul 14, 2015

+1

@jolantz
Copy link

@jolantz jolantz commented Jul 15, 2015

+1

@OGPoyraz
Copy link

@OGPoyraz OGPoyraz commented Jul 15, 2015

+1

@antons-
Copy link

@antons- antons- commented Jul 15, 2015

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

@wenzowski
Copy link

@wenzowski wenzowski commented Jul 15, 2015

👍 this was easy with the old api.

@thelinmichael
Copy link
Contributor

@thelinmichael 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
Copy link

@wenzowski wenzowski commented Jul 17, 2015

@thelinmichael yes, was referring to apps api

@srijak
Copy link

@srijak srijak commented Aug 4, 2015

+1

@jpiepkow
Copy link

@jpiepkow 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
Copy link

@kvanzuijlen 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
Copy link

@kvanzuijlen 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
Copy link

@jpiepkow 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
Copy link

@gabernardone 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
Copy link

@jpiepkow 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
Copy link

@gabernardone gabernardone commented Apr 3, 2017

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

image

@jpiepkow
Copy link

@jpiepkow 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
Copy link

@gabernardone gabernardone commented Apr 3, 2017

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

@jpiepkow
Copy link

@jpiepkow jpiepkow commented Apr 3, 2017

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

@hughrawlinson
Copy link
Member

@hughrawlinson 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
Copy link

@gabernardone 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
Copy link
Member

@hughrawlinson 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
Copy link

@gabernardone gabernardone commented Apr 5, 2017

@hughrawlinson Of Course, my user id is 12160188079

@NicolasHaeffner
Copy link

@NicolasHaeffner 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
Copy link
Member

@hughrawlinson 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
Copy link
Contributor

@JMPerez 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
Copy link

@mcoalson 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
Copy link

@Serdiev 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
Copy link
Member

@asmitter 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
Copy link

@unRob 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
Copy link
Contributor

@JMPerez 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
Copy link

@unRob 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
Copy link

@emilbruckner emilbruckner commented May 25, 2017

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

@sean1rose
Copy link

@sean1rose sean1rose commented Jun 16, 2017

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

@duikb00t
Copy link

@duikb00t duikb00t commented Jun 19, 2017

+1

1 similar comment
@fvaca
Copy link

@fvaca fvaca commented Jul 19, 2017

+1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet