Since the gdrive tool is no longer maintained. I found an official and better way.
Using curl.
- Install Curl
sudo apt install curl
- Create your project credentials on google console. Make an account first if you don't have any.
Create credentials > Configure OAth consent screen (if needed) > Application type > TV and limited input devices > Save your client id and a client secret.
- Verify the device
curl -d "client_id=<client_id>&scope=https://www.googleapis.com/auth/drive.file" https://oauth2.googleapis.com/device/code
Expected response:
{"device_code": "<long string>",
"user_code": "xxx-xxx-xxx",
"expires_in": 1800,
"interval": 5,
"verification_url": "https://www.google.com/device"}
Then go to the https://www.google.com/device
--> Enter "user_code"
--> Give relevant permissions.
- Save the
"device_code"
and "user_code"
values.
- Get Bearer code
curl -d client_id=<client id> -d client_secret=<client secret> -d device_code=<device code> -d grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Adevice_code https://accounts.google.com/o/oauth2/token
Expected Output:
{
"access_token": ".....",
"expires_in": 3599,
"refresh_token": "....",
"scope": "https://www.googleapis.com/auth/drive.file",
"token_type": "Bearer"
}
Save the "access_token"
value.
Start uploading
curl -X POST -L -H "Authorization: Bearer <enter access_token here>" -F "metadata={name :'filename.zip'};type=application/json;charset=UTF-8" -F "file=@filename.zip;type=application/zip" "https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart"
CAUTION
Make zip archives of your files before uploading. The above code works for archived files. I uploaded 10gb archive with the above method successfully.
Source