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

Getting final URL with a URL that redirects using Python

Getting final URL with a URL that redirects using Python

The Spotify API sends you back a URL when authenticating. This URL, redirects you to a previously specified redirect URI (in my case http://localhost:5000) with some parameters that I am after. But so far I can only get to this final URL if I copy paste the URL sent by Spotify into a browser. My question is: how can I obtain this final URL using the redirect URL without a browser, all done only with python.

 

Obtaining the URL:

 

 

 

 

def authenticate_user():
auth_request = requests.get(ENPOINT_USER_AUTH, {
    'client_id': CLIENT_ID,
    'response_type': 'code',
    'redirect_uri': 'http://localhost:5000/',
    'scope': 'playlist-modify-private'
})

 

 

 

 

The result URL:

 

 

 

 

https://accounts.spotify.com/es-ES/login?continue=https%3A%2F%2Faccounts.spotify.com%2Fauthorize%3Fscope%3Dplaylist-modify-private%26response_type%3Dcode%26redirect_uri%3Dhttp%253A%252F%252Flocalhost%253A5000%252F%26client_id%3D3adbd9e...1a42dccff57

 

 

 

 

Copy-paste into browser I get a new URL:

 

 

 

 

http://localhost:5000/?code=AQAVgnC8cnqQ....tnLd4dKlU

 

 

 

 

How can I obtain this final URL just with code? No browsers involved?

Some posts mention urllib, but I have tried to

 

 

 

 

result= urllib.request.urlopen(auth_request.url)

 

 

 

 

And it returns the same exact URL.

Any help much appreciated.

 

Reply
0 Replies

Suggested posts

Staff
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…

Staff
ModeratorStaff / Moderator/ 3 years ago  in Social & Random

Type a product name