C
C
Crash2018-03-01 13:20:42
PHP
Crash, 2018-03-01 13:20:42

How to download files from google drive using PHP?

I am guided by examples here: https://developers.google.com/drive/v3/web/quickst...
And here: https://developers.google.com/drive/v3/web/manage-...
List of files Already removed from the disk, you need to make it possible to download. But here's where it got tricky.
I set the access rights to the widest: https://www.googleapis.com/auth/drive
I'm trying to get the file as follows (Yii2 project):

public function actionDownload($fileId)
{
    $service = GoogleDocsConsole::getService(); // Экземпляр Google_Service_Drive       
    $response = $service->files->export($fileId, 'application/pdf', [
         'alt' => 'media'
    ]);
        
    $content = $response->getBody()->getContents();
    return $content;
}

As a result, I see an error:
Google_Service_Exception
{
"error": {
"errors": [
{
"domain": "global",
"reason": "insufficientPermissions",
"message": "Insufficient Permission"
}
],
"code": 403,
"message": "Insufficient Permission"
}
}

What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question