Announcements

Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

Invalid username - cant get devices

Solved!

Invalid username - cant get devices

Hi

I'm trying get Spotify devices (and eventually set active device) via the web API. I can retrieve track info, but as soon I try to access device or play/pause I get the "Invalid User" reply.

I can see the necesary scopes in the Auth token reply, but I'm missing something.

'token_type': 'Bearer', 'expires_in': 3600, 'scope': 'user-modify-playback-state user-read-playback-state user-read-currently-playing user-read-recently-played'}

 

In other posts the Spotify username is mentioned as a possible error. I use same account in Home assistant and can play/pause with no errors.

 

Thanks

 

 

 

 

    def _set_device(self, *args):
        BASE_URL = 'https://api.spotify.com/v1/'
        DEV_URL = "me/player/devices"
        AUTH_URL = 'https://accounts.spotify.com/api/token'

        auth_response = requests.post(AUTH_URL, {
            'grant_type': 'client_credentials',
            'client_id': '..',
            'client_secret': '..',
            'scope': 'user-modify-playback-state user-read-playback-state user-read-currently-playing user-read-recently-played',
        })

        auth_response_data = auth_response.json()
        access_token = auth_response_data['access_token']

        headers = {
            'Authorization': 'Bearer {token}'.format(token=access_token)
        }
        track_id = '7I6y2ptp8e5zTIxmv8uEjP'
        #r = requests.get(BASE_URL + 'audio-features/' + track_id, headers=headers)
        #r = requests.get(BASE_URL + 'me/player/devices', headers=headers)
        r = requests.get('https://api.spotify.com/v1/me/player/pause', headers=headers)

 

 

 

 

 

Reply

Accepted Solutions
Marked as solution

Welcome to the forum, @nogetfx!

 

It looks like you're using the client credentials flow to authenticate with Spotify. In order to use the player endpoints, you'll want to obtain a token through one of the other OAuth flows, like the authorization code flow. You can find more information about this in our OAuth documentation: https://developer.spotify.com/documentation/general/guides/authorization-guide/

View solution in original post

1 Reply
Marked as solution

Welcome to the forum, @nogetfx!

 

It looks like you're using the client credentials flow to authenticate with Spotify. In order to use the player endpoints, you'll want to obtain a token through one of the other OAuth flows, like the authorization code flow. You can find more information about this in our OAuth documentation: https://developer.spotify.com/documentation/general/guides/authorization-guide/

Suggested posts

Let's introduce ourselves!

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…

ModeratorStaff / Moderator/ 4 years ago  in Social & Random