PHP
PHP
Dropbox: Get Space Usage
See more Dropbox Examples
Demonstrates how to get the Dropbox space usage information for the current user's account.Chilkat PHP Downloads
<?php
use Chilkat2\JsonObject;
use Chilkat2\Rest;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
$rest = new Rest();
// Connect to the www.dropbox.com endpoint.
$bTls = true;
$port = 443;
$bAutoReconnect = true;
try {
$rest->Connect('api.dropboxapi.com', $port, $bTls, $bAutoReconnect);
$rest->AddHeader('Authorization', 'Bearer DROPBOX-ACCESS-TOKEN');
$responseStr = $rest->FullRequestNoBody('POST', '/2/users/get_space_usage');
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
// Success is indicated by a 200 response status code.
if ($rest->ResponseStatusCode != 200) {
// Examine the request/response to see what happened.
echo 'response status code = ', $rest->ResponseStatusCode, "\n";
echo 'response status text = ', $rest->ResponseStatusText, "\n";
echo 'response header: ', $rest->ResponseHeader, "\n";
echo 'response body (if any): ', $responseStr, "\n";
echo "---\n";
echo 'LastRequestStartLine: ', $rest->LastRequestStartLine, "\n";
echo 'LastRequestHeader: ', $rest->LastRequestHeader, "\n";
exit;
}
$jsonResponse = new JsonObject();
$jsonResponse->Load($responseStr);
$jsonResponse->EmitCompact = false;
echo $jsonResponse->Emit(), "\n";
// {
// "used": 3032115,
// "allocation": {
// ".tag": "individual",
// "allocated": 2147483648
// }
// }
//