function getDriveFilesForFolder($app){
// Get the API client and construct the service object.
$client = getClient($app); // function that gets an authorized client instance
$service = new Google_Service_Drive($client);
// we only want files from a specific folder
$q="'".$app->constants->get('GOOGLE_DOCS_MAIN_FOLDER_ID')."' in parents";
$optParams = array(
'q' => $q
);
$results = $service->files->listFiles($optParams);
if (count($results->getFiles()) == 0) {
echo "No files found.<br>";
} else {
echo "Files:<br>";
foreach ($results->getFiles() as $file) {
//var_dump($file);
echo '<br><br>';
echo $file->getName()." (".$file->getId().") ";
}
}
}
这样可以打印出文件名及其ID的列表。
alternateLink
Rest端点的documented here Google_Service_Drive_DriveFile
或Google_Collection
中看不到任何功能
它延伸的alternateLink
将返回
alternateLink
。 如何使用PHP SDK从代码中的$file
对象获取docker-compose.yml
值?
值得一提
答案 0 :(得分:0)
到目前为止,我能够提出的最好的方法是循环遍历文件对象并使用它们的id来使用来自经过身份验证的php客户端的相同访问令牌来获取cURL的文件元数据,如下所示:
private function getFileMetaData($files){
/**
* the php sdk doesnt seem to have a way to get the alternate url (edit url) for a file
* so we'll have to loop over the files and get their metadata using cURL
*/
$metadataArray=[];
foreach ($files as $file) {
$restEndpoint="https://www.googleapis.com/drive/v2/files/".$file->getId();
$ch = curl_init($restEndpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer '.$this->client->getAccessToken()['access_token']
));
$data = curl_exec($ch);
$metadataArray[]=$data;
curl_close($ch);
}
return $metadataArray;
}
这样可行,但确实不是正确的方法。
发布此信息并保持开放状态,希望有人知道正确的方法。