It's doable. All You need to do is to specify the correct scope when authenticating, https://spreadsheets.google.com/feeds
, https://docs.google.com/feeds
and https://www.googleapis.com/auth/drive.file
First, let's see how easy it is for a file with "anyone with link" permissions. We will be calling the API from a browser window.
– Get Your API Key, from Google developers Console (create the app, give it access to Drive API and generate API Key.)
– Get a File ID of a google spreadsheet with permissions set to "Anyone with the link".
Now paste this address to You browser to get a zip archive with your sheet in html format along with a css file: https://www.googleapis.com/drive/v3/files/{FILE_ID}/export?mimeType=application%2Fzip&key={YOUR API KEY}
Remember to fill the adress with Your FILE_ID and an API_KEY.
Now let's do the same on a private file using curl and OAuth authentication.
0. Prepare Your API_KEY, CLIENT_ID and CLIENT_SECRET from Google Developer Console.
1. Verify device and get DEVICE_CODE
curl \
-d 'client_id=[CLIENT_ID]' \
-d 'scope=https://spreadsheets.google.com/feeds https://docs.google.com/feeds https://www.googleapis.com/auth/drive.file' \
https://oauth2.googleapis.com/device/code
2. Go to verification url
https://www.google.com/device
3. get the ACCESS_TOKEN
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
3. OR Refresh the token
curl \
--request POST \
--data 'client_id=[CLIENT_ID]' \
--data 'client_secret=[CLIENT_SECRET]' \
--data 'refresh_token=[REFRESH_TOKEN]' \
--data 'grant_type=refresh_token' \
https://accounts.google.com/o/oauth2/token
4. AND GET YOUR FILE
curl \
-H 'Authorization: Bearer [ACCESS_TOKEN]' \
-H 'Accept: application/json' \
https://www.googleapis.com/drive/v3/files/[FILE_ID]/export?mimeType=application%2Fzip&key=[API_KEY]