Not receiving “webViewLink” in response?

前端 未结 2 1378
耶瑟儿~
耶瑟儿~ 2020-12-22 04:56

After turning on Google Drive API access from the management console and getting my Client ID keys, I followed the sample code (using Python 2.7) and I am able to insert a f

相关标签:
2条回答
  • 2020-12-22 05:17

    The webViewLink property is only returned for public folders, and not the single files inside such folders. You can use that as the base url to construct links to your files.

    0 讨论(0)
  • 2020-12-22 05:20

    The WebViewLink file property can be retrieved by doing something like this:

    $file = $service->files->get($file_id, array('fields' => 'webViewLink'));
    $web_link_view = $file->getWebViewLink();
    

    OR

    $sheetsList = $drive_service->files->listFiles([
      'fields' => 'files(id, name, webViewLink, webContentLink)',
    ]);
    
    $web_link_view = $sheetsList->current()->getWebViewLink();
    

    Pay attention that you should load the file specifying which fields you wanna bring with it (In this case, webViewLink). If you don't do that, only id and name will be available.

    If you also need to configure file permissions, you can do something like:

    $permissions = new \Google_Service_Drive_Permission();
    $permissions->setRole('writer');
    $permissions->setType('anyone');
    
    $drive_service->permissions->create($file_id, $permissions);
    

    Possible values for setRole() and setType() can be found here: https://developers.google.com/drive/api/v3/reference/permissions/create

    0 讨论(0)
提交回复
热议问题