Downloading Files using Google Drive API

See: Google Cloud SDK (gcloud CLI)

Using gcloud cli:

 gcloud auth login --enable-gDRIVE-access

gcloud doesn’t provide command to access google drive.

Install gdrive

brew install gdrive

$ gdrive list
Authentication needed
Go to the following url in your browser:

Enter verification code:

After entering verification code from browser:

$ ls ~/.gdrive

$ gdrive list --order folder,createdTime -m 500 --name-width 0 --absolute

$ gdrive help list
List files
gdrive [global] list [options]

  -c, --config <configDir>             Application path, default: /Users/aung/.gdrive
  --refresh-token <refreshToken>       Oauth refresh token used to get access token (for advanced users)
  --access-token <accessToken>         Oauth access token, only recommended for short-lived requests because of short lifetime (for advanced users)
  --service-account <serviceAccount>   Oauth service account filename, used for server to server communication without user interaction (filename path is relative to config dir)

  -m, --max <maxFiles>       Max files to list, default: 30
  -q, --query <query>        Default query: "trashed = false and 'me' in owners". See
  --order <sortOrder>        Sort order. See
  --name-width <nameWidth>   Width of name column, default: 40, minimum: 9, use 0 for full width
  --absolute                 Show absolute path to file (will only show path from first parent)
  --no-header                Dont print the header
  --bytes                    Size in bytes

-q, –query <query>

–order <sortOrder>

OrderBy sets the optional parameter “orderBy”: A comma-separated list of sort keys. Valid keys are ‘createdTime’, ‘folder’, ‘modifiedByMeTime’, ‘modifiedTime’, ‘name’, ‘name_natural’, ‘quotaBytesUsed’, ‘recency’, ‘sharedWithMeTime’, ‘starred’, and ‘viewedByMeTime’. Each key sorts ascending by default, but may be reversed with the ‘desc’ modifier. Example usage: ?orderBy=folder,modifiedTime desc,name. Please note that there is a current limitation for users with approximately one million files in which the requested sort order is ignored.

Install drive-cli

brew install python@3.9

pip3 install drive-cli

drive login doesn’t work. Got: App is blocked by google

drive login

Leave a Comment

Your email address will not be published. Required fields are marked *