Skip to content

Instantly share code, notes, and snippets.

@Map987
Forked from anoopkcn/google_drive_to_machine.md
Created October 16, 2024 11:21
Show Gist options
  • Save Map987/0e151dc3dee206b6e9c5e4c138dfe7f9 to your computer and use it in GitHub Desktop.
Save Map987/0e151dc3dee206b6e9c5e4c138dfe7f9 to your computer and use it in GitHub Desktop.
Downloading google drive data

Get the file ID:

  1. Go to your Google Drive in your browser.
  2. Right-click (or control-click) the file you want to download and click “Get shareable link”. The link looks like this: https://drive.google.com/open?id=XXXXX. Make note of the file ID “XXXXX”; you will be needing it below.

Get an OAuth token:

  1. Go to OAuth 2.0 Playground
  2. In the “Select the Scope” box, scroll down, expand “Drive API v3”, and select https://www.googleapis.com/auth/drive.readonly
  3. Click “Authorize APIs” and then “Exchange authorization code for tokens”. Copy the “Access token”; you will be needing it below.

Download the file from the command line:

If using OS X or Linux, open the “Terminal” program and enter the following command.

curl -H "Authorization: Bearer YYYYY" https://www.googleapis.com/drive/v3/files/XXXXX?alt=media -o ZZZZZ 

For large files(>50Gb)start from last terminated position

curl -k -H "Authorization: Bearer YYYYY" -o ZZZZZ -C - https://www.googleapis.com/drive/v3/files/XXXXX?alt=media

If using Windows, open the “PowerShell” program and enter the following command.

Invoke-RestMethod -Uri https://www.googleapis.com/drive/v3/files/XXXXX?alt=media -Method Get -Headers @{"Authorization"="Bearer YYYYY"} -OutFile ZZZZZ

In your command, replace “XXXXX” with the file ID from above, “YYYYY” with the access token from above, and “ZZZZZ” with the file name that will be saved (for example, “myFile.mp4” if you’re downloading an mp4 file).

Press Enter and let the download begin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment