Google APIs Node.js Client

171.4.0 · maintenance · verified Tue Apr 21

The `googleapis` package is Google's officially supported Node.js client library for interacting with a wide range of Google APIs. It provides a unified interface for over 200 Google services, including non-GCP APIs like YouTube, Gmail, and Google Drive, as well as some Google Cloud Platform (GCP) services. The library currently stands at version 171.4.0 and sees frequent updates, typically driven by automated API definition generators for individual service modules, leading to regular minor and patch releases. Major version bumps often aggregate breaking changes across various underlying API modules. A key differentiator is its comprehensive coverage of all Google APIs, contrasting with the `@google-cloud/*` libraries which are purpose-built and idiomatic Node.js clients specifically for Google Cloud Platform services. While `googleapis` provides authentication support for OAuth 2.0, API Keys, and JWT tokens, it is explicitly in maintenance mode, meaning new features will not be added, and development prioritizes critical bug fixes and security issues. For new projects utilizing GCP services, Google strongly recommends using the actively developed `@google-cloud/*` client libraries, which often offer gRPC support for improved performance.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Google APIs client library, instantiate the Blogger API client for version v3, and authenticate with an API key to retrieve blog details using `async/await`.

import { google } from 'googleapis';

async function getBlogDetails(blogId: string, apiKey: string) {
  // Each API may support multiple versions. With this sample, we're getting
  // v3 of the blogger API, and using an API key to authenticate.
  const blogger = google.blogger({
    version: 'v3',
    auth: apiKey
  });

  const params = {
    blogId: blogId
  };

  try {
    // Get the blog details
    const res = await blogger.blogs.get(params);
    console.log(`Successfully retrieved blog ID: ${blogId}`);
    console.log(`The blog URL is: ${res.data.url}`);
    console.log(`Blog Title: ${res.data.name}`);
    return res.data;
  } catch (err) {
    console.error('The API returned an error: ' + err);
    throw err;
  }
}

// To run this example, replace 'YOUR_BLOG_ID' and process.env.GOOGLE_API_KEY with actual values.
// A public blog ID can be found via Google APIs Explorer or your own Blogger account.
const BLOG_ID = process.env.BLOG_ID ?? '3213900'; // Example public blog ID
const API_KEY = process.env.GOOGLE_API_KEY ?? ''; // Ensure you have an API key enabled for Blogger API

if (!API_KEY) {
  console.warn('Warning: No GOOGLE_API_KEY provided. This example might fail if the API requires authentication.');
}

getBlogDetails(BLOG_ID, API_KEY)
  .then(details => console.log('Operation complete.'))
  .catch(error => console.error('Failed to get blog details.', error));

view raw JSON →