Categories
Mastering Development

Download Google Drive file owned by some account and shared with my service account

There is an URL of a shared spreadsheet file hosted by Google Drive.

It looks similar to this one

https://docs.google.com/spreadsheets/d/1TFFswncS12FAc-Fsh33dMfL0UK87LCcZZNToV0/edit?usp=sharing

I want to download this file by nodejs app using some Google service account and Google Drive API client library. But as far as I can see that library just doesn’t have such a method or option to download a file by URL.

https://developers.google.com/drive/api/v3/manage-downloads

Instead of that, there is a get method that requires fileId property, and it seems to me that it is not possible to access somebody’s files by that fileId.

So, most probably, I’ll have to generate an authentication token based on service account client_id and private_key and download (actually, exported CSV) with any HTTP client passing the token as a header.

Is that a correct choice and how to authenticate to the app without password?

I have such application environment variables

GOOGLE_FEED_ACCOUNT_TYPE=service_account
GOOGLE_FEED_PROJECT_ID=my-app
GOOGLE_FEED_PRIVATE_KEY_ID=sdf796a7S58FSADF9A8S97FD987AS6D8F75A8Sas
GOOGLE_FEED_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n\n-----END PRIVATE KEY-----\n"
GOOGLE_FEED_CLIENT_EMAIL=my-app@example.com
GOOGLE_FEED_CLIENT_ID=398387234329388162487
GOOGLE_FEED_FOLDER_ID=1QFBASSDFasdfasew3wsD85cHpf-9U

Leave a Reply

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