GSC-analytics / app.py
blazingbunny's picture
Update app.py
4e182e6 verified
raw
history blame
1.25 kB
import streamlit as st
from requests_oauthlib import OAuth2Session
# ... (Load client ID and client secret securely)
# OAuth Configuration
authorization_base_url = 'https://accounts.google.com/o/oauth2/v2/auth'
token_url = 'https://www.googleapis.com/oauth2/v4/token'
redirect_uri = 'your_huggingface_spaces_app_url'
scopes = ['https://www.googleapis.com/auth/webmasters.readonly']
# ... (Streamlit UI - similar to before)
if st.button("Fetch Data"):
google_oauth = OAuth2Session(client_id, scopes=scopes, redirect_uri=redirect_uri)
# Step 1: User authorization
authorization_url, state = google_oauth.authorization_url(authorization_base_url, access_type="offline", prompt="select_account")
st.write("Please authenticate with Google:", authorization_url)
# Step 2: Handle redirect and fetch tokens (modify after user clicks the button)
redirect_response = st.text_input("Paste the full redirect URL here:")
token = google_oauth.fetch_token(token_url, client_secret=client_secret, authorization_response=redirect_response)
# Step 3: Use token in API requests
credentials = google_oauth.authorized
service = build('webmasters', 'v3', credentials=credentials)
# ... (rest of your API request logic)