0
votes

I am trying to download a file from Google Drive to my harddrive. The entire authentication is done in JavaScript and I am receiving a response from the server:

request = gapi.client.drive.files.get({'fileId': id}); request.execute(function(resp) { ........ }

I have the correct scope in order to be allowed to download files:

https://www.googleapis.com/auth/drive

Also the request above is returning me a downloadUrl.

I am trying to send the downloadUrl to PHP, but the download process is failing with a 401 error.

Any suggestion? I have tried to download the file directly in Javascript, but I didn't find a good solution yet.

Thanks and let me know if you have any question. It is my first question here since this one is killing me :D

2
Can you post the exact 401 error my guess is your php script doesn't have access to download it send it the access token from JavaScript. developers.google.com/drive/v3/web/manage-downloadsDaImTo
@DaImTo Yes, that is the problem. But I don't know how to send the access token from JS and if I am doing a new auth on PHP, I am receiving this :<p>Type: Google_Service_Exception</p> <p>Message: Error calling GET googleapis.com/drive/v2/files/…: (403) Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.</p> - Never had this issue before.Johansson Owen

2 Answers

0
votes

Is this a public file or a private file? Are you sending the right auth token to GDrive within PHP? Are there any other warnings/errors along with the 401?

401 with the GDrive API means that you are providing invalid credentials. You must not be supplying the right auth within PHP, or at least not the same auth as you did with JS.

0
votes

Thank you everyone for your help. This topic help me a lot : Newbie Google Drive API (PHP) confusion - what guide/library to use?

The problem was indeed auth in PHP, or better, the lack of it.