React Native
React Native
Dropbox: Get Space Usage
See more Dropbox Examples
Demonstrates how to get the Dropbox space usage information for the current user's account.Chilkat React Native Downloads
import { JsonObject, Rest } from '@chilkat/react-native'
async function chilkatExample() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const rest = new Rest();
// Connect to the www.dropbox.com endpoint.
const bTls = true;
const port = 443;
const bAutoReconnect = true;
try {
await rest.connectAsync('api.dropboxapi.com', port, bTls, bAutoReconnect);
} catch {
console.log(rest.lastErrorText);
return;
}
rest.addHeader('Authorization', 'Bearer DROPBOX-ACCESS-TOKEN');
let responseStr: string;
try {
responseStr = await rest.fullRequestNoBodyAsync('POST', '/2/users/get_space_usage');
} catch {
console.log(rest.lastErrorText);
return;
}
// Success is indicated by a 200 response status code.
if (rest.responseStatusCode !== 200) {
// Examine the request/response to see what happened.
console.log(`response status code = ${rest.responseStatusCode}`);
console.log(`response status text = ${rest.responseStatusText}`);
console.log(`response header: ${rest.responseHeader}`);
console.log(`response body (if any): ${responseStr}`);
console.log('---');
console.log(`LastRequestStartLine: ${rest.lastRequestStartLine}`);
console.log(`LastRequestHeader: ${rest.lastRequestHeader}`);
return;
}
const jsonResponse = new JsonObject();
jsonResponse.load(responseStr);
jsonResponse.emitCompact = false;
console.log(jsonResponse.emit());
// {
// "used": 3032115,
// "allocation": {
// ".tag": "individual",
// "allocated": 2147483648
// }
// }
//
}