Type in your question below and we'll check to see what answers we can find...
Loading article...
Submitting...
If you couldn't find any answers in the previous step then we need to post your question in the community and wait for someone to respond. You'll be notified when that happens.
Simply add some detail to your question and refine the title if needed, choose the relevant category, then post.
Before we can post your question we need you to quickly make an account (or sign in if you already have one).
Don't worry - it's quick and painless! Just click below, and once you're logged in we'll bring you right back here and post your question. We'll remember what you've already typed in so you won't have to do it again.
Please see below the most popular frequently asked questions.
Loading article...
Loading faqs...
Please see below the current ongoing issues which are under investigation.
Loading issue...
Loading ongoing issues...
Generating a Web API SDK access token through my app
According to the Authorization Guide, there are 3 players involved in the authorization process:
- The Spotify auth server.
- Your application (the client) which requests the access token by implementing the authorization flow using your client ID and client Secret after you register the application in the dashboard.
- The end user, who wants to access to a given resource using their Spotify account.
The authorization flow uses scopes to allow your application to access specific resources (playback, playlists, etc..), so the user will be prompted to grant those permissions to your app. Once the user allows your app, the access token is generated. If you want to request a new token, you can use the "refresh token", which is returned on the same JSON response along with the access token. The refresh token can be used later to get a new access token without visiting the grant screen.
Creating a broadcast outlet
If you want to embed the Web Playback SDK within an iframe, you must allow "encrypted-media" and "autoplay" in cases of cross origin iframes. This currently affects Chrome browsers since they introduced Feature Policy which disallows features
within iframes by default.
Playing a song on the user's SpotifySelecting the Web Player from the device menu on the user's Spotify
Once the Web Player SDK is loaded and a new device id is created, you can transfer the playback manually (using the official Spotify app) or via Web API using the Transfer User's Playback API from Playback APIs.
Hope it helps!
Hi Alvaron,
Thanks for the help. This seems to be my updated plan:
Host a static page at AAA.com:
<!DOCTYPE html>
<html>
<head>
<script src="https://sdk.scdn.co/spotify-player.js"></script>
<script>
window.onSpotifyWebPlaybackSDKReady = () => {
const url = new URL(window.location.href);
const token = url.searchParams.get('token');
const player = new Spotify.Player({
name: 'Spotify Web Player',
getOAuthToken: cb => { cb(token); }
});
player.connect();
};
</script>
</head>
<body>
<h1>Spotify Web Player</h1>
</body>
</html>
Request authorization to get access token BBB:
GET https://accounts.spotify.com/authorize?client_id=CCC&response_type=code&redirect_uri=DDD&scope=streaming%20user-read-email%20user-read-private%20user-modify-playback-state
Navigate to AAA.com?token=BBB from within the app
Get user's available devices including { id: "EEE", "name": "Spotify Web Player" }:
GET https://api.spotify.com/v1/me/player/devices -H "Authorization: CCC"
Transfer user's playback to the device we have open:
PUT https://api.spotify.com/v1/me/player -H "Authorization: CCC" { device_ids = ['EEE'], play: false }
Search/play a song on Spotify
Is there a better way to do this?
Using this method, a video player pops up on the phone and therefore does not allow the user to navigate away. What are other ways to do this?
Thanks,
Nikhil
The authorization flow looks good to me. You could skip the API call to retrieve the device id, though. The SDK emits the ready event, which provides the device id:
player.addListener('ready', ({ device_id }) => {
console.log('Ready with Device ID', device_id);
});
Once the event is received, you could transfer the playback via Web API.
I don't fully understand what you mean with the "video player" as the SDK provides music playback capabilities only. Could you please provide more info? what would be the expected behaviour?
Thanks!
Thanks for that tip!
When I go to the hosted url from within a react-native app, and select the device from my Spotify player (and play a song), the video player pops up in the react-native app.
I have attached a video for reference.
Also, the song stops playing after 10 seconds. This is not the case if I visit the app from a url on my Desktop browser.
Hey! Thanks a lot for video. It helped a lot to understand the issue!
I've been talking with the team behind the Web Playback SDK. Turns out the SDK contains an internal empty video tag which makes React Native see it as video content. This might be the reason why a video control pops up.
So, I'm afraid React Native is not supported by the SDK. We will update the documentation accordingly.
It would be interesting to see if the same behaviour happens using Ionic, though.
That explains it - I'm surprised that didn't have a similar effect on my Desktop browser.
What do you recommend I do to play the music in my React app? I'm looking to play the full song without the app being in the forefront (so going to another app on my phone does not stop the song)
Hey! Sorry for my late response!
If your application is based on React (not React Native), you can embed the Web Playback SDK inside the React app and play the full song from there. Bear in mind that moving the playback to the background does not work on iOS platform (but it does work on Desktop and Android).
We will be releasing a new tutorial soon about how to create a simple web player app using the Web Playback SDK, React and Node. Please stay tuned! 🙂
No worries!
Do you have an idea on where mobile functionality is on the roadmap?
Will you also be posting a tutorial on how to create a mobile player app in the near future?
Thanks,
Nikhil
The Web Playback SDK fits perfectly for this use case, but given the current limitation of the SDK with the background playback on iOS platform, I would suggest to take a look to the iOS SDK. This SDK also provides playback capabilities. You can find documentation on the portal and on the project GitHub repository.
Hope it helps!
Thanks for the quick response.
I currently have my own player, am using the iOS SDK and can only play a 30 second version of the song.
The iOS SDK has not been updated in 18 months and is now deprecated - which led to trying to migrate to the Web API.
I do have my own player in the App. Is there a way I can register my player as a device on Spotify such that I can select it using the transfer endpoint and play the full song in my app?
Hey there you, Yeah, you! 😁 Welcome - we're glad you joined the Spotify Community! While you here, let's have a fun game and get…