spotify / web-api-examples

Basic examples to authenticate and fetch data using the Spotify Web API
Apache License 2.0
1.99k stars 1.67k forks source link

Client-Credentials Query #43

Closed Casey6624 closed 4 years ago

Casey6624 commented 4 years ago

Hi, is there any way we can target the https://api.spotify.com/v1/me/player/currently-playing endpoint using the client-credentials method?

We use Spotify as our music source in the office and I would like to grab the data and manipulate it...

Is this possible or do you have to use implicit_grant/ authorization_code?

Austral1a commented 4 years ago

Hey, 1) You have to create onclick event on button or something like this, onClick={() => window.location = "https://accounts.spotify.com/authorize?client_id=${YOUR_CLIENTID}&redirect_uri=${YOUR_REDIRECT}&scope=user-read-private%20user-read-email&response_type=token&state=123"} 2) After this, you will get access_token ( it will be in your URL ), then parse it with "query-string" e.g. By the way here is how it can look let parsed = queryString.parse(window.location.hash) 3) Do XHR request, fetch("https://api.spotify.com/v1/me/player/currently-playing", { method: 'GET', headers: { 'Authorization': 'Bearer ' + parsed.access_token } }) .then(res => res.json()) .then(data => console.log(data)) Screenshot_1

Casey6624 commented 4 years ago

Hey! Thanks for the response, but I know how to do this and your comment refers to Auhorization Code authentication not Client Server like i requested.

I don't want a user to have to login to utilize the API, I want my server to refresh the connection and make requests on behalf of a user

henriquecpp commented 4 years ago

This way is returning invalid user to me