Trying to get the code which arises from the redirected URL when a user approves my application to read their data from the spotify API. The issue is that I need the code to either receive the url that contains the code when the user authenticates the application. I haven't been able to do that through Python yet. I think I need to do this through requests but I don't 1. know what to use 2. know where I should look for what to use.
The code I have so far:
import spotipy
from spotipy.oauth2 import SpotifyOAuth
import os
from pathlib import Path
import requests
client_id = os.environ['']
client_secret = os.environ['']
redirect_uri = 'http://www.example.xyz/'
scope = 'user-read-recently-played user-read-currently-playing user-top-read user-read-private'
cache = Path("cache/")
username = ''
oauth = SpotifyOAuth(client_id, client_secret, redirect_uri, scope=scope, cache_path=cache/f".cache-{username}",username=username)
url = oauth.get_authorize_url()
req = requests.get(url)
red = req.url
print(red)
# code = oauth.parse_response_code(red)
# token = oauth.get_access_token(code=code,as_dict=False)
This is just a test that i'm doing before I attempt to implement this in my larger code (a discord bot) and what I do is that in this code I manually get the redirected url, paste it into the browser and then authenticate the app from there: the page then continues to the redirected page having the authorisation code affixed to the end.
What I want to know is how to get that authorisation code or send it to my script in some way with Python.