下载网址无法在Google Drive API PHP中使用 [英] Download url not working in Google Drive API PHP

查看:82
本文介绍了下载网址无法在Google Drive API PHP中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Google Drive API时遇到问题,我可以使用API​​来获取文件,但无法通过此链接下载.我想,必须进行一些身份验证,但是我已经使用了刷新令牌进行身份验证.请参见下面的代码

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?

推荐答案

要获取downloadUrl,您需要获取文件的元数据.您可以使用获取方法来实现.该方法将返回文件资源表示形式.在此资源中,有一个 downloadUrl 属性.如果您能够访问文件并已经获得URL,则身份验证设置应该没有问题.可能存在权限问题,您可能无权访问某些驱动器文件,但是如果没有收到错误消息,则在那里也应该没事.我对PHP并不是特别熟悉,但是也许您没有正确下载它? 在这里似乎是另外一种方式.

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.

我还建议您检出Drive PHP 快速入门应用作为参考.

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

这篇关于下载网址无法在Google Drive API PHP中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆