Google API Client Library for PHP

The official PHP client for calling Google APIs like Gmail, Drive, YouTube, and Sheets with built-in OAuth 2.0 auth handling.

SDK
Composer
vv2.19.4
9,805stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
73/100Good
Development Activity40
Maintenance56
Community96
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
71/100Good
Architecture76
Code Quality78
Innovation62
Learning Curve68

The Google API Client Library for PHP is Google’s officially supported SDK for calling Google’s REST APIs — Gmail, Drive, Calendar, YouTube, Sheets, and hundreds of others — from PHP applications. A single Google\Client class handles OAuth 2.0 authentication (including service accounts, refresh tokens, and application default credentials), while per-API service classes (generated into the companion google/apiclient-services package) expose each API’s methods as typed PHP calls instead of raw HTTP requests.

Google describes the library as “complete and in maintenance mode”: critical bugs and security issues are addressed, but new features are not added here — Google Cloud Platform APIs (Datastore, Pub/Sub, Cloud Storage) are steered instead toward the separate google/cloud client libraries, which follow a different, more idiomatic-per-service design. This client remains the recommended path for the classic Google Workspace and consumer APIs.

What You Get

  • A Google\Client class that manages OAuth 2.0 flows, API keys, service-account credentials, token refresh, and caching in one place.
  • Typed service classes for hundreds of Google APIs (Gmail, Drive, Calendar, YouTube, Sheets, Analytics, and more), pulled in via the google/apiclient-services dependency.
  • Built-in support for batching multiple API calls into a single HTTP request via Google\Http\Batch.
  • Media upload/download helpers (Google\Http\MediaFileUpload) for APIs like Drive that transfer large files in chunks.
  • Runnable examples covering common flows — simple file upload, service account auth, batching — under examples/.

Common Use Cases

  • Sending email programmatically through a user’s Gmail account via the Gmail API.
  • Reading, writing, and managing files in Google Drive from a PHP backend.
  • Syncing events with a user’s Google Calendar from a scheduling or booking application.
  • Pulling analytics or Sheets data into a PHP application for reporting or automation.

Under The Hood

Architecture: src/Client.php is the library’s single entry point — it owns the HTTP client (Guzzle), the auth configuration, caching, and logging, and hands out configured Google\Service\* instances on request. src/AuthHandler/ and dependency on google/auth implement the actual OAuth 2.0 / service-account / ADC credential flows, while src/Http/ implements request building, batching (Batch.php), and chunked media upload/download. The per-API service classes themselves live in the separate google/apiclient-services package (regenerated from Google’s API discovery documents) and are pulled in as a dependency rather than vendored directly, keeping this repository focused on the client/auth/transport layer.

Tech Stack: PHP 8.1+, built on guzzlehttp/guzzle and guzzlehttp/psr7 for HTTP, google/auth for credential handling, firebase/php-jwt for JWT signing (service-account auth), and monolog/monolog for logging. Static analysis is enforced via phpstan.neon.dist and style via phpcs.xml.dist (PHP_CodeSniffer).

Code Quality: tests/ contains around 30 PHPUnit test files plus a tests/Google/ subtree, run under phpunit.xml.dist, alongside examples/ that double as documentation and lightweight integration smoke tests. SECURITY.md documents a responsible-disclosure process, and CI runs a GitHub Actions test workflow on every change; Google explicitly states the library is in maintenance mode, so changes trend toward bug/security fixes over new features.

API Design: Because typed methods are generated per Google API, calling any of the hundreds of supported APIs follows the same shape ($service = new Google\Service\Drive($client); $service->files->list($params);), so once a developer learns the pattern for one Google API, it transfers directly to any other API exposed through this client — at the cost of a fairly large generated-code dependency (apiclient-services) even when only one API is used.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search