'webViewLink' is empty/null when using PHP code sample

亡梦爱人 提交于 2019-12-01 21:26:36

As a workaround, if you have folder ID, you can use https://googledrive.com/host/FOLDER_ID_HERE

I wrote a small JavaScript app that lists your public folders. Can you confirm your folder is showing in the list? If it's not showing, it's not shared publicly and thus there's no webViewLink:

https://googledrive.com/host/0B0YvUuHHn3Mna3Rzb19tLTYyOXc/

the page is hosted in Google drive itself so it's being served by Google Drive and accessing Google Drive and for anyone that asks, no, the Universe did not implode :-)

A "few" years later here's a working sample with a service account. I have a G Suite account and in https://admin.google.com/example.com/AdminHome?chromeless=1#OGX:ManageOauthClients I have set my API client to API scope https://www.googleapis.com/auth/drive and then

include_once __DIR__ . '/../vendor/autoload.php';
$client = new Google_Client();
$client->setAuthConfig('my_auth.json');
$client->addScope('https://www.googleapis.com/auth/drive');
$client->setSubject('admin.example.com');
$service = new Google_Service_Drive($client);
$x = $service->files->listFiles([
  'spaces' => 'drive', // this doesn't seem necessary
  'q' => 'name = "download"',
  'fields' => 'files(id, name, webViewLink, webContentLink)',
]);

Do pay attention to the fields argument: it does not retrieve anything but id and name if you leave it out.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!