Getting final URL with a URL that redirects using Python
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page