php - 如何在 php 中使用 Google 控制台服务帐户通过 Google Drive API 获取文件夹/文件列表
问题描述
我在过去的几天里正在搜索这个东西,以使用服务帐户获取子文件夹/文件列表没有任何方法可以请任何人帮助我如何获得它?
我使用了以下一些代码:-
define('FOLDER_ID', '1acTBwQK8QH5OERZYwuqSnt6sMDdf4V2c');
require_once './vendor/autoload.php';
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . __DIR__ . '/service-account.json');
function getGoogleClient()
{
return getServiceAccountClient();
}
function getServiceAccountClient()
{
try {
// Create and configure a new client object.
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/drive.appfolder"
);
return $client;
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
}
}
$client = getGoogleClient();
$service = new Google_Service_Drive($client);
// $student_folder = $service->children->listChildren('1HmwwEabelrR_q5MQqkUWMrlYsTgtLDdr');
$optParams = array(
'fields' => '*'
);
$results = $service->files->get(FOLDER_ID, $optParams);
$permissions = $results->getPermissions();
$files = $service->files->get(FOLDER_ID);
echo '<pre>';
print_r($files);
echo '</pre>';
它根据文件夹ID返回我的主文件夹名称或详细信息我将其设置为静态但我如何获取子文件夹/文件列表并创建文件夹和上传文件我很困惑
如果有任何其他方式 pelese 向我推荐了我如何设置它,如果有任何博客,那么还请添加一个链接以供参考。
我需要它在 PHP 中使用任何库。
感谢您的帮助。
解决方案
推荐阅读
- python - 如何将函数动态添加到类并保留函数在类中返回的内容?
- python - How can I set the diagonal of an N-dim tensor to 0 along given dims?
- c# - C# Word.Interop 更改 ContentControl DropDownList 的文本
- netlogo - 如何纠正错误:找不到没有数字的列表的平均值
- r - 如何根据另一行中的范围对 R 中的列表进行条件子集化
- asp.net - 文件已下载但其他按钮随后被禁用并且不会在 asp.net 中触发
- google-chrome - 如果消息泛滥,F8/pause 在 Chrome DevTools 中不起作用
- javascript - 根据范围参数可以从数字组成多少组
- xpages - Xpages - 通过按钮单击时 JS 代码无法执行
- postgresql - 获取每个季度的第一条实时记录