我想通过Google提供的php客户端为 zip文件在Google驱动器上生成共享链接。
使用Google Drive的php客户端,我可以设置权限(通过查看drive gui中的文件权限来确认):
$config = [
'type' => 'anyone',
'role' => 'reader',
'withLink' => true,
//'allowFileDiscovery' => false
];
$tempPermission = new Google_Service_Drive_Permission($config);
$ret = $this->service->permissions->create($file, $tempPermission);
echo '<pre>';
print_r($ret);
$files = $this->service->files->get($file);
print_R($files);
但是我不确定从何处获取物理网址。
这是设置烫发后文件对象的输出:
Google_Service_Drive_DriveFile Object
(
[collection_key:protected] => spaces
[appProperties] =>
[capabilitiesType:protected] => Google_Service_Drive_DriveFileCapabilities
[capabilitiesDataType:protected] =>
[contentHintsType:protected] => Google_Service_Drive_DriveFileContentHints
[contentHintsDataType:protected] =>
[copyRequiresWriterPermission] =>
[createdTime] =>
[description] =>
[driveId] =>
[explicitlyTrashed] =>
[exportLinks] =>
[fileExtension] =>
[folderColorRgb] =>
[fullFileExtension] =>
[hasAugmentedPermissions] =>
[hasThumbnail] =>
[headRevisionId] =>
[iconLink] =>
[id] => 1CU_nTm06ATlf2s54890oY62NyEzCGgyf
[imageMediaMetadataType:protected] => Google_Service_Drive_DriveFileImageMediaMetadata
[imageMediaMetadataDataType:protected] =>
[isAppAuthorized] =>
[kind] => drive#file
[lastModifyingUserType:protected] => Google_Service_Drive_User
[lastModifyingUserDataType:protected] =>
[md5Checksum] =>
[mimeType] => application/zip
[modifiedByMe] =>
[modifiedByMeTime] =>
[modifiedTime] =>
[name] => restorepoint_2019_08_02_07_32_57.zip
[originalFilename] =>
[ownedByMe] =>
[ownersType:protected] => Google_Service_Drive_User
[ownersDataType:protected] => array
[parents] =>
[permissionIds] =>
[permissionsType:protected] => Google_Service_Drive_Permission
[permissionsDataType:protected] => array
[properties] =>
[quotaBytesUsed] =>
[shared] =>
[sharedWithMeTime] =>
[sharingUserType:protected] => Google_Service_Drive_User
[sharingUserDataType:protected] =>
[size] =>
[spaces] =>
[starred] =>
[teamDriveId] =>
[thumbnailLink] =>
[thumbnailVersion] =>
[trashed] =>
[trashedTime] =>
[trashingUserType:protected] => Google_Service_Drive_User
[trashingUserDataType:protected] =>
[version] =>
[videoMediaMetadataType:protected] => Google_Service_Drive_DriveFileVideoMediaMetadata
[videoMediaMetadataDataType:protected] =>
[viewedByMe] =>
[viewedByMeTime] =>
[viewersCanCopyContent] =>
[webContentLink] =>
[webViewLink] =>
[writersCanShare] =>
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
如果有人能弄清楚如何从生成时间起的一小时内将其设置为过期,则奖励积分(在文档关于php客户端中找不到与此有关的任何信息)
答案 0 :(得分:0)
我找到了解决方案。需要这样做:
$files = $this->service->files->get($file,array("fields"=>"webViewLink"));
print_R($files);
填充者:webViewLink