-
Notifications
You must be signed in to change notification settings - Fork 0
/
google-drive.php
46 lines (34 loc) · 1.19 KB
/
google-drive.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
require __DIR__ . '/vendor/autoload.php';
use Google\Service\Drive;
function queryGdrive($sharedDriveId){
session_start();
$client = new Google_Client();
$client->setRedirectUri('http://localhost/8000');
$client->setScopes(Drive::DRIVE);
$client->setAuthConfig('google-credentials.json');
$driveService = new Drive($client);
$parameters = [
'corpora' => 'drive',
'includeItemsFromAllDrives' => true,
'driveId' => $sharedDriveId,
'supportsAllDrives' => true,
'q' => "'{$sharedDriveId}' in parents and mimeType = 'application/vnd.google-apps.folder'",
'spaces' => 'drive',
'fields' => 'files(id, name)',
];
$results = $driveService->files->listFiles($parameters);
$foldersDatas = [];
try {
foreach ($results->getFiles() as $file) {
$baseurl = "https://drive.google.com/drive/folders/";
$datas = [];
$datas["name"] = $file->getName();
$datas["url"] = $baseurl.$file->getId();
$foldersDatas[] = $datas;
}
} catch (Exception $e) {
echo "An error occurred: " . $e->getMessage()."\n";
}
return $foldersDatas;
}