blazingbunny commited on
Commit
ab3dc2e
·
verified ·
1 Parent(s): 18cd106

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -2,13 +2,18 @@ import streamlit as st
2
  from requests_oauthlib import OAuth2Session
3
  from googleapiclient.discovery import build
4
  from datetime import datetime, timedelta
 
5
 
6
  # ************ Credentials (Important Security Note - See above warning) ***************
7
  CLIENT_ID = "243651188615-q9970hsa72e028jnu3qqsup6vl02epnn.apps.googleusercontent.com"
8
- CLIENT_SECRET = st.secrets["google_search_console_api"] # Retrieve from Hugging Face Secrets
9
  REDIRECT_URI = 'https://huggingface.co/spaces/blazingbunny/GSC-analytics/'
10
  # *********************************************
11
 
 
 
 
 
12
  # OAuth Configuration
13
  AUTHORIZATION_BASE_URL = 'https://accounts.google.com/o/oauth2/v2/auth'
14
  TOKEN_URL = 'https://www.googleapis.com/oauth2/v4/token'
@@ -16,13 +21,13 @@ SCOPES = ['https://www.googleapis.com/auth/webmasters.readonly']
16
 
17
  # Initiate OAuth Flow
18
  google_oauth = OAuth2Session(CLIENT_ID, redirect_uri=REDIRECT_URI, scope=SCOPES)
19
- authorization_url, state = google_oauth.authorization_url(AUTHORIZATION_BASE_URL, access_type="offline", prompt="select_account")
20
 
21
  # Streamlit UI
22
  st.title("Search Analytics Viewer")
23
 
24
  # Authenticate with Google
25
  if st.button("Authenticate with Google"):
 
26
  st.write("Please authenticate with Google:", authorization_url)
27
 
28
  # Handle Redirect
 
2
  from requests_oauthlib import OAuth2Session
3
  from googleapiclient.discovery import build
4
  from datetime import datetime, timedelta
5
+ import json
6
 
7
  # ************ Credentials (Important Security Note - See above warning) ***************
8
  CLIENT_ID = "243651188615-q9970hsa72e028jnu3qqsup6vl02epnn.apps.googleusercontent.com"
9
+ CLIENT_SECRET_JSON = st.secrets["google_search_console_api"]
10
  REDIRECT_URI = 'https://huggingface.co/spaces/blazingbunny/GSC-analytics/'
11
  # *********************************************
12
 
13
+ # Load client secret JSON
14
+ client_secret_data = json.loads(CLIENT_SECRET_JSON)
15
+ CLIENT_SECRET = client_secret_data["client_secret"]
16
+
17
  # OAuth Configuration
18
  AUTHORIZATION_BASE_URL = 'https://accounts.google.com/o/oauth2/v2/auth'
19
  TOKEN_URL = 'https://www.googleapis.com/oauth2/v4/token'
 
21
 
22
  # Initiate OAuth Flow
23
  google_oauth = OAuth2Session(CLIENT_ID, redirect_uri=REDIRECT_URI, scope=SCOPES)
 
24
 
25
  # Streamlit UI
26
  st.title("Search Analytics Viewer")
27
 
28
  # Authenticate with Google
29
  if st.button("Authenticate with Google"):
30
+ authorization_url, state = google_oauth.authorization_url(AUTHORIZATION_BASE_URL, access_type="offline", prompt="select_account")
31
  st.write("Please authenticate with Google:", authorization_url)
32
 
33
  # Handle Redirect