0

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

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • 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. https://developers.google.com/drive/v3/web/manage-downloads – Linda Lawton - DaImTo Jun 01 '17 at 12:59
  • @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 :

    Type: Google_Service_Exception

    Message: Error calling GET https://www.googleapis.com/drive/v2/files/0BzoBu-s2PDkDRjhHU1RLZFhkOEk?alt=media: (403) Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.

    - Never had this issue before.
    – Johansson Owen Jun 01 '17 at 14:05

2 Answers2

0

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.

JonLuca
  • 850
  • 6
  • 25
0

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.