ccolas commited on
Commit
eb07038
1 Parent(s): 0c95d20

Update app_utils.py

Browse files
Files changed (1) hide show
  1. app_utils.py +11 -8
app_utils.py CHANGED
@@ -4,6 +4,7 @@ import os
4
  import pickle
5
  import spotipy
6
  import spotipy.util as sp_util
 
7
 
8
  dir_path = os.path.dirname(os.path.realpath(__file__))
9
 
@@ -47,19 +48,21 @@ def new_get_client(session):
47
  cache_handler=cache_handler,
48
  show_dialog=True)
49
  print('Here4')
 
 
 
 
 
 
 
 
 
50
 
51
  if not auth_manager.validate_token(cache_handler.get_cached_token()):
 
52
  # Step 1. Display sign in link when no token
53
  auth_url = auth_manager.get_authorize_url()
54
  st.markdown(f'[Click here to log in]({auth_url})', unsafe_allow_html=True)
55
- login = centered_button(st.button, 'Log in', n_columns=5)
56
- print('Here6')
57
- if login:
58
- print('Here7')
59
- sp = spotipy.Spotify(auth_manager=auth_manager)
60
- user_id = sp.me()['id']
61
- else:
62
- sp, user_id = None, None
63
  return sp, user_id
64
 
65
 
 
4
  import pickle
5
  import spotipy
6
  import spotipy.util as sp_util
7
+ import requests
8
 
9
  dir_path = os.path.dirname(os.path.realpath(__file__))
10
 
 
48
  cache_handler=cache_handler,
49
  show_dialog=True)
50
  print('Here4')
51
+ sp, user_id = None, None
52
+
53
+ if requests.get("code"):
54
+ # Step 2. Being redirected from Spotify auth page
55
+ auth_manager.get_access_token(requests.get("code"))
56
+ print('Here7')
57
+ sp = spotipy.Spotify(auth_manager=auth_manager)
58
+ user_id = sp.me()['id']
59
+
60
 
61
  if not auth_manager.validate_token(cache_handler.get_cached_token()):
62
+ print('Here6')
63
  # Step 1. Display sign in link when no token
64
  auth_url = auth_manager.get_authorize_url()
65
  st.markdown(f'[Click here to log in]({auth_url})', unsafe_allow_html=True)
 
 
 
 
 
 
 
 
66
  return sp, user_id
67
 
68