Sample code for 30+ languages & platforms
React Native

Get a List of Message IDs in GMail User's Mailbox

See more GMail REST API Examples

Demonstrates how to get a list of message IDs in a GMail mailbox. The "userId" can be either the user's email address or the special value "me" to indicate the authenticated user.

Chilkat React Native Downloads

React Native
import { Http, HttpResponse, JsonObject } 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 = 'ACCESS_TOKEN';

  http.accept = 'application/json';

  const resp = new HttpResponse();
  try {
    await http.httpNoBodyAsync('GET', 'https://www.googleapis.com/gmail/v1/users/userId/messages', resp);
  } catch {
    console.log(http.lastErrorText);
    return;
  }

  console.log(`Response Status Code: ${resp.statusCode}`);

  const jsonResponse = new JsonObject();
  jsonResponse.load(resp.bodyStr);
  jsonResponse.emitCompact = false;
  console.log(jsonResponse.emit());

  if (resp.statusCode !== 200) {
    console.log('Failed.');
    return;
  }

  // {
  //   "messages": [
  //     users.messages Resource
  //   ],
  //   "nextPageToken": string,
  //   "resultSizeEstimate": unsigned integer
  // }

  let id = '';
  let threadId = '';

  const resultSizeEstimate = jsonResponse.intOf('resultSizeEstimate');
  let i = 0;
  const countI = jsonResponse.sizeOfArray('messages');
  while (i < countI) {
    jsonResponse.i = i;
    id = jsonResponse.stringOf('messages[i].id');
    threadId = jsonResponse.stringOf('messages[i].threadId');
    i++;
  }
}