Member-only story

Automate Working with Google Drive

Nikhil Verma
2 min readMar 20, 2021

I am sharing here the code to upload or download some files from google drive. I simply used suite of google libraries as:-

from googleapiclient.discovery import build 
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from googleapiclient.http import MediaIoBaseDownload
from googleapiclient.http import MediaFileUpload

Make sure that you should be having credentials to use google APIs.

For the same you must enable API and get keys from https://developers.google.com/drive/api/v3/enable-drive-api

Search and Select the API you are looking for — google drive API in my case

Then go to credentials and Create “Credentials compatible with this API”

Now download the Credentials.json file since the same will be used while working with the python code.

Now run the code I am sharing below via simple comand:-

$ python googleDriveFileUploadOrDownload.py

Doing this will prompt you to a screen on your browser where you have to login once.

--

--

Nikhil Verma
Nikhil Verma

Written by Nikhil Verma

Knowledge shared is knowledge squared | My Portfolio https://lihkinverma.github.io/portfolio/ | My blogs are living document, updated as I receive comments

No responses yet