Sample code for 30+ languages & platforms
React Native

Google Search Console API - Delete

See more Google Search Console Examples

Demonstrates how to remove a site from the set of the user's Search Console sites.

Chilkat React Native Downloads

React Native
import { Http, HttpResponse, 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.

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

  // In this example, Get a Google Search Console OAuth2 Access Token, the access
  // token was saved to a JSON file.  This example fetches the access token from the file..
  const jsonToken = new JsonObject();
  jsonToken.loadFile('qa_data/tokens/googleSearchConsole.json');
  if (!jsonToken.hasMember('access_token')) {
    console.log('No access token found.');
    return;
  }

  const http = new Http();
  http.authToken = jsonToken.stringOf('access_token');

  const sbUrlToDelete = new StringBuilder();
  sbUrlToDelete.append('https://www.example.com/');
  sbUrlToDelete.encode('url', 'utf-8');

  const sbUrl = new StringBuilder();
  sbUrl.append('https://www.googleapis.com/webmasters/v3/sites/');
  sbUrl.appendSb(sbUrlToDelete);

  // Our URL looks like this:  https://www.googleapis.com/webmasters/v3/sites/https%3A%2F%2Fwww.example.com%2F
  console.log(sbUrl.getAsString());

  const url = sbUrl.getAsString();
  const resp = new HttpResponse();
  try {
    await http.httpNoBodyAsync('DELETE', url, resp);
  } catch {
    console.log(http.lastErrorText);
    return;
  }

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

  if (statusCode >= 400) {
    console.log(resp.bodyStr);
    console.log('Failed.');
  }
}