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

https://github.com/prasmussen/gdrive

brew install gdrive

$ gdrive list
Authentication needed
Go to the following url in your browser:
https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=...%2Fdrive&state=state

Enter verification code:

After entering verification code from browser:

$ ls ~/.gdrive
token_v2.json

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

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

global:
  -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)

options:
  -m, --max <maxFiles>       Max files to list, default: 30
  -q, --query <query>        Default query: "trashed = false and 'me' in owners". See https://developers.google.com/drive/search-parameters
  --order <sortOrder>        Sort order. See https://godoc.org/google.golang.org/api/drive/v3#FilesListCall.OrderBy
  --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>

https://developers.google.com/drive/api/v3/search-shareddrives
https://developers.google.com/drive/api/v3/ref-search-terms#operators

–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

https://github.com/nurdtechie98/drive-cli

pip3 install drive-cli

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

https://github.com/nurdtechie98/drive-cli/issues/114

drive login

Leave a Comment

Your email address will not be published.

four × three =