dqtok88424 2014-11-20 06:50
浏览 40
已采纳

下载网址无法在Google Drive API PHP中使用

I am having issue with the Google Drive API, i was able to fetch the files using API But i can't download via this link. I guess, must some auth, but i have used refresh tokens to authenticate.Please see below for my code

$this->load->library('google-api-php-client/src/Google_Client');
                include APPPATH . '/libraries/google-api-php-client/src/contrib/Google_DriveService.php';
                // Library Files Configuration to get access token and Refresh Token
                $client = new Google_Client();
                $client->setAccessType('offline'); // default: offline
                $client->setApplicationName('xxx'); //name of the application
                $client->setClientId('yyyy'); //insert your client id
                $client->setClientSecret('zzz'); //insert your client secret
                $client->setScopes(array('https://www.googleapis.com/auth/drive'));
                $service = new Google_DriveService($client);

                $client->refreshToken($drive_data->refreshtoken);
                $client->getAccessToken();
                $parameters = array();
                $files = $service->files->listFiles($parameters);
foreach ($files['items'] as $key => $items)
                            {
<a href="<?php echo $files['items'][$key]['downloadUrl'];  ?>">Download</a>
}

Anybody knows how to get the download url with authentication?

  • 写回答

3条回答 默认 最新

  • douliao8402 2014-11-21 23:37
    关注

    To get downloadUrls, you need to get the metadata of a file. You can do so by using the get method. The method will return a File Resource representation. In this resource, there is a downloadUrl property. If you're able to access the files and get the URL already, then there should be no problem with your authentication setup. There could be permission issues where you may not have access to certain drive files, but if you receive no error for it, you should be fine there too. I am not particularly familiar with PHP, but perhaps you are not downloading it correctly? Here it seems to be done differently.

    I also suggest that you check out the Drive PHP Quickstart App to use as a reference.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?