brim-borium/spotify_sdk

Access to User's Playlist

Raj2503 opened this issue · 7 comments

I am working on a project where I want to play the User's private playlists.

Is there any way of implementing this using spotify_sdk?

Hi @Raj2503 :)

From the spotify documentiaon (for the android sdk)

play(java.lang.String uri)

Play the given Spotify uri. Supported uris currently include:

  • Track - example: spotify:track:6rqhFgbbKwnb9MLmUQDhG6 Album - example: spotify:album:2VYSDvc0ZdcfkXDcYVjHs6
  • Artist - example: spotify:artist :4SJSGUVZ04tezaGrxc96EE
  • Playlist - example: spotify:<user<:playlist::7hJSGUVZ04tevaGixc38EG

NOTE Capabilities.canPlayOnDemand must be true to play a Track.

Introduced in com.spotify.protocol.client.RequiredFeatures#FEATURES_V1
Parameters:

  • uri - to play

Returns:

  • a pending call result that can be used to track the success/failure of this command

So I think this should be possible, I am not sure regarding private playlists. You probably have to use a specific scope from here in order to get access to a private playlist.

Custom scopes can be used in the

connectToSpotifyRemote()

And I see that we are currently not using the given scopes on android with connectToSpotifyRemote() because we are using the app remote sdk, this automatically takes the app-remote-control scope.

For scopes you can use getAuthenticationToken() using this flow. This will give you a access token but should also register your app.

Hey @brim-borium,
Thanks for responding so soon :)

I have used connectToSpotifyRemote() to gain remote access to Spotify with
scope: 'user-read-private,playlist-read-private'.

But to play a track or playlist, you need a Spotify URI corresponding to it.
I am able to play tracks and public playlists(like top 50/100 charts) by hardcoding their URI with I gain from the Spotify App.
Example - SpotifySdk.play(spotifyUri: 'spotify:track:7dlinhODpxkOVRCA8LhEGb');
(Similar to what you have demonstrated here).

So is there any inbuilt way to retrieve the URI instead of hardcoding?
Cuz I think if we are able to gain public playlist URI directly then in similar ways we can get private playlists URI too.

Currently spotify_sdk only implements auth and remote sdk's from spotify for controlling the playback (and some other stuff 😄) so we can't get for example a users playlist URI.

If you want to get a URI you have to use the web api with the token generated fromgetAuthenticationToken() with the scopes you used.

The web api you have to implement by yourself using for example the http-package

Have a look at the web api reference for getting a users playlists on what you have to send to the web api

Okay, I was trying to avoid using web API and get a faster way to do that but looks like I don't have a choice now lol.
I will look into the web API guides.

But do try to implement it.
It would really helpful to Flutter-Spotify developers if you are able to come up with something of that sort.

Thanks a lot :)

I concur. Web API is the way to go. You need to call https://api.spotify.com/v1/me/playlists/. What you need to try is request the playlist-read-private scope using this SDK and then see if you can reuse the access token on the web API. It should work on iOS. Not sure about Android.

You can use the spotify package to perform the web requests. To reuse the token I have a long standing PR which I hope gets merged soon.

And I see that we are currently not using the given scopes on android with connectToSpotifyRemote() because we are using the app remote sdk, this automatically takes the app-remote-control scope.

For scopes you can use getAuthenticationToken() using this flow. This will give you a access token but should also register your app.

@brim-borium we should document this. On iOS there is no difference between connectToSpotifyRemote and getAuthenticationToken as they are both using the same mechanism. Maybe we should add a paragraph about "additional scopes" and state that in that case use getAuthenticationToken() to minimize confusion.

EDIT: We could go as far as removing the additional scopes argument from the connectToSpotify() method. I notice that also on the web implementation there is overlap between the connectToSpotify() and getAuthenticationToken() methods. Perhaps we could rethink the API for those 2 methods to make things simpler.