Hello ,
i am working on a project, downloading data from Google Drive and displaying them in my streamlit app, all done by using google drive api which itself utilizes a client_secret_file.json
is there a way to use the data found in this JSON file in my secrets file?
the function uses the whole JSON file as a parameter so im not sure which credentials to take from it.
here’s the function that uses the file
def Create_Service(client_secret_file, api_name, api_version, *scopes):
print(client_secret_file, api_name, api_version, scopes, sep=‘-’)
CLIENT_SECRET_FILE = client_secret_file
API_SERVICE_NAME = api_name
API_VERSION = api_version
SCOPES = [scope for scope in scopes[0]]
print(SCOPES)
cred = None
pickle_file = f'token_{API_SERVICE_NAME}_{API_VERSION}.pickle'
# print(pickle_file)
if os.path.exists(pickle_file):
with open(pickle_file, 'rb') as token:
cred = pickle.load(token)
if not cred or not cred.valid:
if cred and cred.expired and cred.refresh_token:
cred.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(CLIENT_SECRET_FILE, SCOPES)
cred = flow.run_local_server()
with open(pickle_file, 'wb') as token:
pickle.dump(cred, token)
try:
service = build(API_SERVICE_NAME, API_VERSION, credentials=cred)
print(API_SERVICE_NAME, 'service created successfully')
return service
except Exception as e:
print('Unable to connect.')
print(e)
return None
If you’re deploying your app to the Streamlit Community Cloud, you can use the built-in secrets management on the platform to store the contents from the secrets file.
Please see
Next, to use it in the app you can call it like so:
hello data professor, sadly this did not work
i had a temporary solution which was to place the client_secrets_file within the streamlit secrets just as you suggested, and use the function json.loads to pass the variable as argument instead of the path , it works locally but when the app is hosted it won’t work and i get the error “TypeError: expected str, bytes or os.PathLike object, not dict”
“UPDATE”
upon further inspections , i tried to pass the client_secrets_file.json directly and still got an error only on the hosted app which is “raise Error(“could not locate runnable browser”)”
does this have to do with streamlit cloud hosting ?
here’s the project github link : VinDazy/Isimm-Study-Hub (github.com)
Thank you
yes i have already activated the google drive api,
my problem is that the application works just fine locally but when hosted it won’t work, even tho they’re working from the same project files
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.