MatteoScript commited on
Commit
0d8eb4c
1 Parent(s): e9968ba

Update google_function.py

Browse files
Files changed (1) hide show
  1. google_function.py +4 -5
google_function.py CHANGED
@@ -139,18 +139,17 @@ def local_storage_set(key, value):
139
  return st_javascript(f"localStorage.setItem('{key}', '{value}');")
140
 
141
  def connetti_google():
142
- redirect = 'https://matteoscript-streamlitchat-new.hf.space'
143
  load_dotenv()
144
  json_variable_str = os.getenv("JSON_GOOGLE")
 
145
  with open("./credentials.json", "w") as f:
146
  f.write(json_variable_str)
147
- flow = InstalledAppFlow.from_client_secrets_file("./credentials.json", SCOPES, redirect_uri=redirect)
148
  token = local_storage_get("token")
149
  print('------------1------------------')
150
  print(token)
151
  if token and token != '':
152
  print('------------2------------------')
153
- #local_storage_set("token", '')
154
  flow.fetch_token(code=token)
155
  st.session_state.creds = flow.credentials
156
  print(st.session_state.creds)
@@ -160,7 +159,7 @@ def connetti_google():
160
  auth_code = st.query_params.get("code")
161
  if auth_code:
162
  local_storage_set("token", auth_code)
163
- time.sleep(2)
164
  print('**************************************************************')
165
  print(auth_code)
166
  nav_script = """<meta http-equiv="refresh" content="0; url='%s'">""" % (redirect)
@@ -189,7 +188,7 @@ def connetti_google_2():
189
  if creds and creds.expired and creds.refresh_token:
190
  creds.refresh(Request())
191
  else:
192
- flow = InstalledAppFlow.from_client_secrets_file("./credentials.json", SCOPES, redirect_uri='https://matteoscript-streamlitchat-new.hf.space')
193
  #creds = flow.run_local_server(port=8501, open_browser=False)
194
  creds = flow.run_console()
195
  with open("token.json", "w") as token:
 
139
  return st_javascript(f"localStorage.setItem('{key}', '{value}');")
140
 
141
  def connetti_google():
 
142
  load_dotenv()
143
  json_variable_str = os.getenv("JSON_GOOGLE")
144
+ URL_REDIRECT = os.getenv('URL_REDIRECT')
145
  with open("./credentials.json", "w") as f:
146
  f.write(json_variable_str)
147
+ flow = InstalledAppFlow.from_client_secrets_file("./credentials.json", SCOPES, redirect_uri=URL_REDIRECT)
148
  token = local_storage_get("token")
149
  print('------------1------------------')
150
  print(token)
151
  if token and token != '':
152
  print('------------2------------------')
 
153
  flow.fetch_token(code=token)
154
  st.session_state.creds = flow.credentials
155
  print(st.session_state.creds)
 
159
  auth_code = st.query_params.get("code")
160
  if auth_code:
161
  local_storage_set("token", auth_code)
162
+ time.sleep(0.7)
163
  print('**************************************************************')
164
  print(auth_code)
165
  nav_script = """<meta http-equiv="refresh" content="0; url='%s'">""" % (redirect)
 
188
  if creds and creds.expired and creds.refresh_token:
189
  creds.refresh(Request())
190
  else:
191
+ flow = InstalledAppFlow.from_client_secrets_file("./credentials.json", SCOPES, redirect_uri=URL_REDIRECT)
192
  #creds = flow.run_local_server(port=8501, open_browser=False)
193
  creds = flow.run_console()
194
  with open("token.json", "w") as token: