Rahulk2197 commited on
Commit
76516dc
·
verified ·
1 Parent(s): d0f1f62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -19
app.py CHANGED
@@ -1,15 +1,15 @@
1
- import os
2
- import pickle
3
- from google_auth_oauthlib.flow import InstalledAppFlow
4
- from google.auth.transport.requests import Request
5
  import streamlit as st
6
- import hashlib
7
  from googleapiclient.discovery import build
 
8
  from googleapiclient.errors import HttpError
 
 
 
9
 
10
  # Constants
11
  CREDS_FILE = 'token.pickle'
12
- CREDENTIALS_FILE = 'details.json'
13
  SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
14
  SPREADSHEET_ID = "17KIBySu21Oh0ajtyo4A9jUTjnwOIl69KlqNlTfszrXQ"
15
  RANGE_NAME = "Sheet1!A:C"
@@ -63,20 +63,11 @@ def get_credentials():
63
  with open(CREDS_FILE, 'wb') as token:
64
  pickle.dump(creds, token)
65
  return creds
66
-
67
  flow = InstalledAppFlow.from_client_secrets_file(CREDENTIALS_FILE, SCOPES)
68
- auth_url, _ = flow.authorization_url(prompt='consent') # Generate authorization URL
69
- st.write(f"Please go to this URL to authorize: [Authorize URL]({auth_url})")
70
-
71
- # Prompt the user to input the authorization code
72
- code = st.text_input("Enter the authorization code")
73
-
74
- if code:
75
- creds = flow.fetch_token(code=code) # Exchange authorization code for tokens
76
- with open(CREDS_FILE, 'wb') as token:
77
- pickle.dump(creds, token)
78
- return creds
79
- return None
80
 
81
  # Sign Up Page
82
  def signup(service):
 
 
 
 
 
1
  import streamlit as st
2
+ from google_auth_oauthlib.flow import InstalledAppFlow
3
  from googleapiclient.discovery import build
4
+ from google.auth.transport.requests import Request
5
  from googleapiclient.errors import HttpError
6
+ import pickle
7
+ import os
8
+ import hashlib
9
 
10
  # Constants
11
  CREDS_FILE = 'token.pickle'
12
+ CREDENTIALS_FILE = 'webapp.json'
13
  SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
14
  SPREADSHEET_ID = "17KIBySu21Oh0ajtyo4A9jUTjnwOIl69KlqNlTfszrXQ"
15
  RANGE_NAME = "Sheet1!A:C"
 
63
  with open(CREDS_FILE, 'wb') as token:
64
  pickle.dump(creds, token)
65
  return creds
 
66
  flow = InstalledAppFlow.from_client_secrets_file(CREDENTIALS_FILE, SCOPES)
67
+ creds = flow.run_local_server(port=0)
68
+ with open(CREDS_FILE, 'wb') as token:
69
+ pickle.dump(creds, token)
70
+ return creds
 
 
 
 
 
 
 
 
71
 
72
  # Sign Up Page
73
  def signup(service):