Warm tip: This article is reproduced from stackoverflow.com, please click
google-drive-api google-contacts-api

Not able Download the (non-public) file from Google Drive which site-users select

发布于 2020-03-27 15:42:25

We are implementing a functionality through which a site user can upload a certain file (let's say PDF) from its machine or from his/her google drive account.

If user selects google drive option, through google drive api, a pop up will open asking the credentials and then select file. At this point, a download-url (which contains file id) has been generated. On the submission of the form, we are trying to read the bytes from this download-url but getting unauthorized error.

We have checked the same code for "public" file and it is working.

My question is, in this scenario, only public files can be downloaded? What if I want to download non-public file - which site users are selecting from Google Drive.

Questioner
Alok KaduDeshmukh
Viewed
60
DaImTo 2020-01-31 16:38

You cant download a file just because you have the download Url to it you need to have access to it. A file that is public is owned by everyone or no one so you would have permission to download it. A file that is owned by a user you must have the permission "or Access" of that user in order to download it.

When you authenticated the user to get a list of their files. You were granted an access token this access token grants your application access to the users account. There for this access token must be used to download the file.