Sample code for 30+ languages & platforms
React Native

Empty Trash

See more Google Drive Examples

Permanently deletes all of the user's trashed files.

Chilkat React Native Downloads

React Native
import { AuthGoogle, Rest } from '@chilkat/react-native'

async function chilkatExample() {
  // It requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  // This example uses a previously obtained access token having permission for the 
  // Google Drive scope.

  const gAuth = new AuthGoogle();
  gAuth.accessToken = 'GOOGLE-DRIVE-ACCESS-TOKEN';

  const rest = new Rest();

  // Connect using TLS.
  const bAutoReconnect = true;
  await rest.connectAsync('www.googleapis.com', 443, true, bAutoReconnect);

  // Provide the authentication credentials (i.e. the access token)
  rest.setAuthGoogle(gAuth);

  let jsonResponse: string;
  try {
    jsonResponse = await rest.fullRequestNoBodyAsync('DELETE', '/drive/v3/files/trash');
  } catch {
    console.log(rest.lastErrorText);
    return;
  }

  // A successful response will have a status code equal to 204 and the response body is empty.
  // (If not successful, then there should be a JSON response body with information..)
  if (rest.responseStatusCode !== 204) {
    console.log(`response status code = ${rest.responseStatusCode}`);
    console.log(`response status text = ${rest.responseStatusText}`);
    console.log(`response header: ${rest.responseHeader}`);
    console.log(`response JSON: ${jsonResponse}`);
    return;
  }

  console.log('Trash Emptied!');
}