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?

图片转代码服务由CSDN问答提供 功能建议

我遇到了Google Drive API的问题,我能够使用API​​获取文件但是我不能 通过此链接下载。 我想,必须有一些身份验证,但我已经使用刷新令牌进行身份验证。请参阅下面的代码

  $ this-&gt; load-&gt; library('google-  api-php-client / src / Google_Client'); 
包括APPPATH。  '/libraries/google-api-php-client/src/contrib/Google_DriveService.php'; 
 //库文件配置获取访问令牌和刷新令牌
 $ client = new Google_Client(); 
 $ client-  &GT; setAccessType( '离线');  // default:offline 
 $ client-&gt; setApplicationName('xxx');  //应用程序的名称
 $ client-&gt; setClientId('yyyy');  //插入您的客户端ID 
 $ client-&gt; setClientSecret('zzz');  //插入您的客户端密码
 $ client-&gt; setScopes(array('https://www.googleapis.com/auth/drive')); 
 $ service = new Google_DriveService($ client); 
 \  n $ client-&gt; refreshToken($ drive_data-&gt; refreshtoken); 
 $ client-&gt; getAccessToken(); 
 $ parameters = array(); 
 $ files = $ service-&gt; files-&gt;  listFiles($ parameters); 
foreach($ files ['items'] as $ key =&gt; $ items)
 {
&lt; a href =“&lt;?php echo $ files ['items'] [$ key  ] ['downloadUrl'];?&gt;“&gt;下载&lt; / a&gt; 
} 
   
 
 

有谁知道如何通过身份验证获取下载网址?< / p>

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

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条)

相关推荐 更多相似问题