or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

batch-operations.mdclient-services.mdhttp-transport.mdindex.mdjson-error-handling.mdmedia-operations.mdoauth2-auth.mdutilities.md
tile.json

tessl/maven-com-google-api-client--google-api-client

The Google APIs Client Library for Java is a flexible, efficient, and powerful Java client library for accessing any HTTP-based API on the web, not just Google APIs.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/com.google.api-client/google-api-client@2.8.x

To install, run

npx @tessl/cli install tessl/maven-com-google-api-client--google-api-client@2.8.0

index.mddocs/

Google API Client for Java

The Google APIs Client Library for Java is a flexible, efficient, and powerful Java client library for accessing any HTTP-based API on the web, not just Google APIs. It provides OAuth 2.0 authentication, lightweight XML and JSON data models, protocol buffer support, and access to generated libraries for Google APIs.

Package Information

  • Package Name: google-api-client
  • Package Type: maven
  • Language: Java
  • Group ID: com.google.api-client
  • Artifact ID: google-api-client
  • Installation: Add to your Maven pom.xml:
<dependency>
  <groupId>com.google.api-client</groupId>
  <artifactId>google-api-client</artifactId>
  <version>2.8.0</version>
</dependency>

Or to your Gradle build.gradle:

implementation 'com.google.api-client:google-api-client:2.8.0'

Core Imports

import com.google.api.client.googleapis.services.AbstractGoogleClient;
import com.google.api.client.googleapis.services.json.AbstractGoogleJsonClient;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;

Basic Usage

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;

import java.io.IOException;
import java.security.GeneralSecurityException;

public class GoogleApiExample {
    private static final JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance();
    
    public static void main(String[] args) throws IOException, GeneralSecurityException {
        // Create HTTP transport
        HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        
        // Load credentials (example with service account)
        GoogleCredential credential = GoogleCredential.fromStream(
            new FileInputStream("path/to/service-account-key.json"))
            .createScoped(Arrays.asList("https://www.googleapis.com/auth/cloud-platform"));
        
        // Use the transport and credentials with specific Google API clients
        // (specific API clients would extend AbstractGoogleJsonClient)
    }
}

Architecture

The Google API Client for Java is built around several key architectural components:

  • HTTP Transport Layer: Provides HTTP transport implementations (Java.net, Apache HttpClient) with SSL/TLS support and mutual TLS (mTLS) capabilities
  • Authentication System: Complete OAuth 2.0 implementation with support for various credential types (service accounts, user credentials, compute engine credentials)
  • Client Framework: Abstract base classes for building type-safe API clients with JSON and generic data model support
  • Media Operations: Resumable upload and download functionality for large files with progress tracking
  • Batch Processing: Efficient batch request processing to reduce API call overhead
  • Error Handling: Structured JSON error response handling with detailed error information
  • Request Management: Automatic retry logic, request initialization, and parameter validation

Capabilities

HTTP Transport

Core HTTP transport implementations with SSL/TLS support and mutual TLS capabilities for secure communication with Google APIs.

// Java.net transport
public static NetHttpTransport newTrustedTransport() 
    throws GeneralSecurityException, IOException;

// Apache HTTP transport  
public static ApacheHttpTransport newTrustedTransport()
    throws GeneralSecurityException, IOException;

HTTP Transport

OAuth2 Authentication

Complete OAuth 2.0 authentication system supporting various credential types including service accounts, user credentials, and compute engine metadata server authentication.

public class GoogleCredential extends Credential {
    public static GoogleCredential fromStream(InputStream keyStream)
        throws IOException;
    
    public GoogleCredential createScoped(Collection<String> scopes);
}

public class GoogleAuthorizationCodeFlow extends AuthorizationCodeFlow {
    public static class Builder extends AuthorizationCodeFlow.Builder {
        public GoogleAuthorizationCodeFlow build();
    }
}

OAuth2 Authentication

Client Services

Abstract base classes and request handling framework for building type-safe Google API clients with automatic JSON parsing and error handling.

public abstract class AbstractGoogleClient {
    protected AbstractGoogleClient(Builder builder);
    public final HttpRequestFactory getRequestFactory();
    public final String getApplicationName();
}

public abstract class AbstractGoogleJsonClient extends AbstractGoogleClient {
    public final JsonFactory getJsonFactory();
    public JsonObjectParser getObjectParser();
}

Client Services

Media Operations

Resumable upload and download functionality for large files with built-in progress tracking, error recovery, and configurable chunk sizes.

public final class MediaHttpUploader {
    public MediaHttpUploader upload(GenericUrl initiationRequestUrl, HttpContent content);
    public void setProgressListener(MediaHttpUploaderProgressListener progressListener);
    public void setChunkSize(int chunkSize);
}

public final class MediaHttpDownloader {
    public void download(GenericUrl requestUrl, OutputStream outputStream);
    public void setProgressListener(MediaHttpDownloaderProgressListener progressListener);
}

Media Operations

Batch Operations

Efficient batch request processing to combine multiple API calls into a single HTTP request, reducing network overhead and improving performance.

public final class BatchRequest {
    public BatchRequest queue(HttpRequest request, Class<T> dataClass, 
        Class<E> errorClass, BatchCallback<T, E> callback);
    public void execute() throws IOException;
}

public interface BatchCallback<T, E> {
    void onSuccess(T t, HttpHeaders responseHeaders) throws IOException;
    void onFailure(E e, HttpHeaders responseHeaders) throws IOException;
}

Batch Operations

JSON Error Handling

Structured JSON error response parsing and exception handling with detailed error information from Google API responses.

public class GoogleJsonResponseException extends HttpResponseException {
    public GoogleJsonError getDetails();
    public static GoogleJsonResponseException from(JsonFactory jsonFactory, 
        HttpResponse response);
}

public final class GoogleJsonError extends GenericJson {
    public Integer getCode();
    public String getMessage();
    public List<ErrorInfo> getErrors();
}

JSON Error Handling

Utilities

Core utility classes providing version information, certificate management, and common functionality used throughout the library.

public final class GoogleUtils {
    public static final String VERSION;
    public static final Integer MAJOR_VERSION;
    public static final Integer MINOR_VERSION;
    public static final Integer BUGFIX_VERSION;
    
    public static synchronized KeyStore getCertificateTrustStore()
        throws IOException, GeneralSecurityException;
}

Utilities