Monday, June 21, 2021

Downloading a file from Google Drive using PyDrive

 #!pip install Pydrive


from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth 
from oauth2client.client import GoogleCredentials

auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
#Authentication happens only once and 
# a file adc.json is created once authentication is done.

file_id = "1nBBfiZOoZToCaGsLxU3s_FRcFcg0Swkk"   #ID OF YOUR GDRIVE FILE.
#THE ID IS PART BETWEEN ..../d/   AND /view...............
# https://drive.google.com/file/d/1nBBfiZOoZToCaGsLxU3s_FRcFcg0Swkk/view?usp=sharing
downloaded = drive.CreateFile({"id": file_id})
downloaded.GetContentFile("MyFile.csv")

No comments:

Post a Comment

How to check local and global angular versions

 Use the command ng version (or ng v ) to find the version of Angular CLI in the current folder. Run it outside of the Angular project, to f...