Helo, I'm trying to code a React app which gets current song from Spotify and plays/pauses the song. However I can't pause or play the current song.
const pauseURL = 'https://api.spotify.com/v1/me/player/pause'
const [token, setToken] = useState('')
const [player, setPlayer] = useState({})
useEffect(() => {
if (localStorage.getItem('accessToken')) {
setToken(localStorage.getItem('accessToken'))
}
}, [token])
const onPause = () => {
axios.put(pauseURL, {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: 'Bearer' + token,
},
})
This is the pause function, and gets the correct token 100%. It always gives 401 error. But it gets the necessary token. When I try it in Postman with the token it pauses or plays the song.
useEffect(() => {
getCurrentInfo()
}, [token, user])
return (
<Image
onClick={() => onPause()}
className="circlePhoto"
src={data.item.album.images[1].url}
/>