Skip to content

Instantly share code, notes, and snippets.

@jrichardsz
Created January 26, 2022 05:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrichardsz/8d3488402a21f576e38ef5e7b66ec805 to your computer and use it in GitHub Desktop.
Save jrichardsz/8d3488402a21f576e38ef5e7b66ec805 to your computer and use it in GitHub Desktop.
google drive upload
tps://developers.google.com/drive/api/v3/quickstart/python
from __future__ import print_function
import pickle
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
# https://developers.google.com/analytics/devguides/config/mgmt/v3/quickstart/service-py
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
SCOPES = 'https://www.googleapis.com/auth/drive'
CLIENT_SECRET_FILE = 'client_secret.json'
credentials = ServiceAccountCredentials.from_json_keyfile_name(
CLIENT_SECRET_FILE, scopes=SCOPES)
# https://developers.google.com/drive/api/v3/quickstart/python
service = build('drive', 'v3', credentials=credentials)
# Call the Drive v3 API
results = service.files().list(
pageSize=10, fields="nextPageToken, files(id, name)").execute()
items = results.get('files', [])
if not items:
print('No files found.')
else:
print('Files:')
for item in items:
print(u'{0} ({1})'.format(item['name'], item['id']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment