I have looked at several posts here about issues very close to this one including one that is exactly the same but no one gave an answer so I am going to give it a go. I am very new to Python. My current homework is to connect to Spotify using their API. According to the documentation on authorization code flow in Spotify. the response to the authorization request should provide two items: code and state.
After I send my request
def authenticate_user():
auth_code = requests.get(ENPOINT_USER_AUTH, {
'client_id': CLIENT_ID,
'response_type': 'code',
'redirect_uri': 'https://www.example.com/',
'scope': 'playlist-modify-private'
})
print(f'Auth code: {auth_code}')
I get a Auth code: <Response [200]>. The response however does not include a code or state. What comes with the response though, is a URL that I can copy-paste into the browser which will redirect me to a callabck URL with the code in it.
My issue here is, I want to save that code into a variable in my Python code. This copy-pasting into a browser can't be the way to do this.
My other problem is that I really don't know what a callback server/redirect is and how to use or set it up to extract this information, or how do achieve this in my python code.
Basically a lot of beginer' questions I apologize. But it's been hours of research and reading and I really would like some input.
This is what the redirect URL looks like after pasting the URL I get in the response.
https://www.example.com/?code=AQAqA0eYYk......JLVUomOR0ziDTcIupZoU
I hope this is clear and I am making sense.
Thank you in advance.
Oh, and I know about Spotipy and that it's supposed to simplify things but I am not interested. I want to learn to use the Spotify aPI.
To make it short and clear: how can I obtain this "code" from their response URL and save it into a variable in my python code programmatically?
EDIT:
Let's say that I want to keep a main.py for the logic and a service.py for the for the localhost services.
Once I have authenticated the user and I get the URL that redirects, how can I feed this URL to my service to get the final URL. I want to be able to send requests from my main.py to the service and get the data in the response rather than keeping everything on the service side.