-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
456 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import os | ||
import google.auth.exceptions | ||
from google_auth_oauthlib.flow import InstalledAppFlow | ||
from googleapiclient.discovery import build | ||
from google.oauth2.credentials import Credentials | ||
|
||
# list shared files id | ||
creds = None | ||
SCOPES = ['https://www.googleapis.com/auth/drive'] | ||
|
||
if os.path.exists('token.json.json'): | ||
creds = Credentials.from_authorized_user_file('token.json.json', SCOPES) | ||
else: | ||
flow = InstalledAppFlow.from_client_secrets_file('credentials.json.json', SCOPES) | ||
creds = flow.run_local_server(port=0) | ||
|
||
# Save the credentials.json for future runs | ||
with open('token.json.json', 'w') as token: | ||
token.write(creds.to_json()) | ||
|
||
try: | ||
drive_service = build('drive', 'v3', credentials=creds) | ||
results = drive_service.drives().list(pageSize=10).execute() | ||
drives = results.get('drives', []) | ||
|
||
if not drives: | ||
print('No shared drives found.') | ||
else: | ||
for drive in drives: | ||
print(f"Shared Drive Name: {drive['name']}, ID: {drive['id']}") | ||
except google.auth.exceptions.GoogleAuthError as e: | ||
print(f"Authentication failed: {e}") |
Oops, something went wrong.