spotify-web-api-node icon indicating copy to clipboard operation
spotify-web-api-node copied to clipboard

WebapiError with api.play

Open edelciomolina opened this issue 5 years ago • 2 comments

Please, can you provide a sample to play a music or playlist?

I´m getting this error in the play method

WebapiError {name: "WebapiError", message: "Not Found", statusCode: 404}

When I try this:

const auth = require('spotify-personal-auth')
const SpotifyWebApi = require('spotify-web-api-node')

auth.config({
    clientId: 'aaaaaaaaaa' 
    clientSecret: 'bbbbbbbbb' 
    scope: ['user-modify-playback-state', 'user-top-read'], 
    path: './tokens.json',  
    redirectUri: 'http://localhost:8888/redirect',
})

const api = new SpotifyWebApi()

auth.token()
    .then(([token, refresh]) => {
        api.setAccessToken(token)
        api.setRefreshToken(refresh)
        return api.getMyTopTracks()
    })
    .then((data) => api.play({ uris: ['spotify:track:6KBsivP3Of4z2x6uNMAyE3'] }))
    .catch(console.log)

edelciomolina avatar Jun 25 '20 02:06 edelciomolina

i think you need to pass just the uri, trim off spotify & track using .split(':')[2]

edit: this doesnt work for me either. I am not sure how to fix this.

Rkubinski avatar Sep 10 '20 17:09 Rkubinski

Did you find any way to make this work? Also, did you have to first connect the Spotify player using the SDK.

ghost avatar Nov 28 '21 08:11 ghost