Sample code for 30+ languages & platforms
React Native

List all Labels in the User's Mailbox

See more GMail REST API Examples

List all Labels in the GMail User's Mailbox

Chilkat React Native Downloads

React Native
import { Http, JsonObject, StringBuilder } 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 http = new Http();
  http.authToken = 'GMAIL-ACCESS-TOKEN';

  const userId = 'me';
  http.setUrlVar('userId', userId);

  const url = 'https://www.googleapis.com/gmail/v1/users/{$userId}/labels';

  http.sessionLogFilename = 'c:/temp/qa_output/sessionLog.txt';

  // Get the list of GMail labels as JSON.
  const sb = new StringBuilder();
  try {
    await http.quickGetSbAsync(url, sb);
  } catch {
    console.log(http.lastErrorText);
    return;
  }

  const json = new JsonObject();
  json.loadSb(sb);
  json.emitCompact = false;
  console.log(json.emit());

  if (http.lastStatus !== 200) {
    console.log('Failed.');
    return;
  }
}