Spaces:
Running
Running
Create google_auth.py
Browse files- google_auth.py +17 -0
google_auth.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from google.oauth2.credentials import Credentials
|
2 |
+
from googleapiclient.discovery import build
|
3 |
+
from google_auth_oauthlib.flow import InstalledAppFlow
|
4 |
+
# Define OAuth 2.0 scopes
|
5 |
+
SCOPES = {os.getenv('Google_scopes')}
|
6 |
+
config = {os.getenv('Google_Secret')}
|
7 |
+
def auth():
|
8 |
+
api_service_name = "drive"
|
9 |
+
api_version = "v3"
|
10 |
+
flow = InstalledAppFlow.from_client_config(config, scopes=SCOPES)
|
11 |
+
credentials = flow.run_local_server(port=5000)
|
12 |
+
drive = build(api_service_name, api_version, credentials=credentials)
|
13 |
+
drive.about().get(fields="user").execute()
|
14 |
+
|
15 |
+
# Use the Drive API client to fetch user information
|
16 |
+
user_info = drive.about().get(fields="user").execute()
|
17 |
+
return user_info
|