About this project

The Google APIs Client Library for PHP enables server-side interaction with Google APIs such as Gmail, Drive, and YouTube. It is officially supported by Google but is considered complete and in maintenance mode, meaning only critical bugs and security issues will be addressed, with no new features added. For Google Cloud Platform APIs (e.g., Datastore, Cloud Storage, Pub/Sub, Compute Engine), Google recommends using the dedicated Google Cloud client libraries instead. **Requirements** - PHP 8.0 or higher **Installation** - Preferred method: Composer (`composer require google/apiclient`). The library depends on `google/apiclient-services`, which provides up-to-date API wrappers. It is recommended to pin to a specific version of `google/apiclient-services` in production to avoid breaking changes. - Alternative: Download a release zip file and include the autoloader. - To reduce dependencies, you can use the `Google\Task\Composer::cleanup` task to keep only specific services (e.g., Drive, YouTube) and remove unused ones. **Basic Usage** - Include the autoloader and create a `Google\Client` instance. - Set application name, developer key, or authentication credentials. - Use generated service classes (e.g., `Google\Service\Books`) to make API calls. **Authentication** - OAuth 2.0 for web applications: set auth config, scopes, redirect URI, and exchange authorization code for access token. - Service accounts: use `GOOGLE_APPLICATION_CREDENTIALS` environment variable or set auth config directly. Domain-wide delegation can impersonate users via `setSubject`. - The `authorize` method returns an authorized Guzzle client for direct HTTP requests. **HTTP Client and Caching** - Uses Guzzle as the default HTTP client, allowing custom handlers and middleware. - Supports PSR-6 compatible caching libraries (e.g., `cache/filesystem-adapter`) to improve performance. - Debugging HTTP requests can be done using tools like Charles. **Handling Non-JSON Responses** - Some APIs return XML by default; you can request JSON by adding `'alt' => "json"` to optional parameters. - Null fields are stripped by default; use `Google\Model::NULL_VALUE` to explicitly set null. **Support and Examples** - Examples are available in the `examples/` directory, including file uploads and service accounts. - For support, use the google-api-php-client tag on StackOverflow or file issues on GitHub for bugs. - Feature requests should be core library requests; API-specific requests should go to the respective API teams. **Code Quality** - Coding style violations can be checked and fixed via Composer scripts. This library is suitable for integrating with Google APIs in PHP applications, with comprehensive documentation in the `docs/` folder.