简体   繁体   中英

How to display current storage used in service account with Google Drive API using PHP?

Can I ask if how will I display the current storage used in my service account of Google Drive API?

I tried to call it in fields but its not working.

$parameters['fields'] = 'files(storage), nextPageToken';

I can't seem to find a post here by typing the title but I can't find any.

How about using "About: get" of Drive API? When this is reflected to the PHP script using googleapis for PHP, it becomes as follows.

Sample script:

$service = new Google_Service_Drive($client); // Please use your "$client".
$res = $service->about->get(['fields' => 'storageQuota']);
$storageQuota = $res -> getStorageQuota();
print_r($storageQuota);

// When you want to retrieve the value of "usage` of "storageQuota", you can do it as follows.
$usage = $storageQuota -> getUsage();
echo $usage;

When above script is run, the following value is obtained.

{
  "limit": "###",
  "usage": "###",
  "usageInDrive": "###",
  "usageInDriveTrash": "###"
}

Reference:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM