from flask import Flask,request,url_for,session,redirect
import spotipy
from spotipy.oauth2 import SpotifyOAuth
import time
def create_app():
app = Flask(__name__)
app.secret_key = "b_5#y2LF4Q8z\n\xec]/"
app.config['SESSION_COOKIE_NAME'] = 'Cookie'
token_information = "token_info"
@app.route('/')
def login():
spotify_oauth = spotify_oauth_oluştur()
auth_url = spotify_oauth.get_authorize_url()
return redirect(auth_url)
@app.route('/sarkilari_cek')
def sarkilari_cek():
try:
token_info = token_infos()
except:
print("user not logged in")
return redirect("/")
sp = spotipy.Spotify (auth=token_info['access_token'])
return sp.current_user_saved_tracks(limit=50,offset = 0)
def token_infos():
token_info = session.get(token_information,None)
if not token_info:
raise Exception("User not logged in")
now = int(time.time())
is_expired = token_info['expires_at'] - now < 60
if is_expired:
sp_oauth = spotify_oauth_oluştur()
token_info = sp_oauth.refresh_access_token(token_info['refresh_token'])
return token_info
@app.route('/redirect')
def redirectPage():
spotify_oauth = spotify_oauth_oluştur()
session.clear()
code = request.args.get('code')
token_info = spotify_oauth.get_access_token(code)
session[token_information] = token_info
return redirect(url_for('sarkilari_cek',_external = True))
def spotify_oauth_oluştur():
return SpotifyOAuth(
client_id="b4a448c907cf42d2a2d80f5f2e11029a",
client_secret="client secret",
redirect_uri=url_for('redirectPage',_external = True),
scope="user-library-read"
)
return app
sürekli user not logged in yazıp yönlendirmeye çalışıyor, giriş yapılmasına izin vermiyor bunun sebebi ne olabilir