PHPackages                             tomshaw/google-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. tomshaw/google-api

ActiveLibrary[API Development](/categories/api)

tomshaw/google-api
==================

A Laravel Google API Client.

v0.14.1(3w ago)601.8k5[1 PRs](https://github.com/tomshaw/google-api/pulls)MITPHPPHP ^8.5CI passing

Since Oct 16Pushed 1w ago1 watchersCompare

[ Source](https://github.com/tomshaw/google-api)[ Packagist](https://packagist.org/packages/tomshaw/google-api)[ RSS](/packages/tomshaw-google-api/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (33)Versions (45)Used By (0)

GoogleApi ☁️
============

[](#googleapi-️)

[![tests](https://github.com/tomshaw/google-api/actions/workflows/run-tests.yml/badge.svg?branch=master)](https://github.com/tomshaw/google-api/actions/workflows/run-tests.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/80ea43e978328376c250ebbb85fd7908e5b437b551198886957b56d53a7f2ef5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f6d736861772f676f6f676c652d6170693f7374796c653d666c61742663616368655365636f6e64733d33363030)](https://packagist.org/packages/tomshaw/google-api)[![Total Downloads](https://camo.githubusercontent.com/3511f4db16f7a73bb062542dee0a736f08f4a27fd5c094f82b57f1caec50e543/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f6d736861772f676f6f676c652d6170693f7374796c653d666c61742663616368655365636f6e64733d33363030)](https://packagist.org/packages/tomshaw/google-api)[![PHP Version](https://camo.githubusercontent.com/90161141f7c004ba6688b18abd7005d8fefc8b1776ccf612f7e27bc33c7a38af/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f746f6d736861772f676f6f676c652d6170692f7068703f7374796c653d666c61742663616368655365636f6e64733d33363030)](https://packagist.org/packages/tomshaw/google-api)[![License](https://camo.githubusercontent.com/ff641a2f0afae0f558c184782d1ba7d09c11b74e2bd4108bc36f99d6ea975658/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f6d736861772f676f6f676c652d6170693f7374796c653d666c61742663616368655365636f6e64733d33363030)](https://github.com/tomshaw/google-api/blob/master/LICENSE)

A Google OAuth 2.0 Laravel Service Client.

Requirements
------------

[](#requirements)

- PHP ^8.5
- Laravel ^13.0

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require tomshaw/google-api
```

If you're facing a timeout error then increase the timeout for composer:

```
{
    "config": {
        "process-timeout": 600
    }
}
```

Next publish the configuration file:

```
php artisan vendor:publish --provider="TomShaw\GoogleApi\Providers\GoogleApiServiceProvider" --tag=config

```

Run the migration if you wish to use database token storage adapter:

```
php artisan migrate

```

To avoid shipping all 200 Google API's you should specify the services you wish to use in your `composer.json`:

```
{
    "scripts": {
        "pre-autoload-dump": "Google\\Task\\Composer::cleanup"
    },
    "extra": {
        "google/apiclient-services": [
            "Gmail",
            "Calendar"
        ]
    }
}
```

Configuration
-------------

[](#configuration)

Here's a brief explanation of the application configuration file used to set up a Google API client:

- `token_storage_adapter`: Sets the default token storage adapter to use. Developers can implement their own custom solution.
- `auth_config`: This is the path to the JSON file that contains your Google API client credentials.
- `application_name`: This is the name of your application.
- `prompt`: This is the type of prompt that will be presented to the user during the OAuth2.0 flow. The `Prompt::Consent` prompt asks the user to grant your application access to the scopes you're requesting.
- `approval_prompt`: This is another setting for the OAuth2.0 flow. The `ApprovalPrompt::Auto` setting means that the user will only be prompted for approval the first time they authenticate your application.
- `access_type`: This is set to `AccessType::Offline` to allow your application to access the user's data when the user is not present.
- `include_grant_scopes`: This is set to true to include the scopes from the initial authorization in the refresh token request.
- `service_scopes`: These are the scopes your application is requesting access to.

The `prompt`, `approval_prompt`, and `access_type` options accept the `TomShaw\GoogleApi\Enums\Prompt`, `ApprovalPrompt`, and `AccessType` enums (plain strings still work).

The Google API client uses these settings to handle the OAuth2.0 flow and interact with the Google APIs.

Basic Usage
-----------

[](#basic-usage)

Authorizing the application and persisting the token.

> Google APIs must have OAuth 2.0 authorization credentials downloaded from the [Google Developer Console](https://console.cloud.google.com/apis). See the application configuration to specify the location of your credentials.

```
namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use TomShaw\GoogleApi\GoogleClient;
use Illuminate\Http\Request;

class GoogleAuthController extends Controller
{
    public function index(GoogleClient $client)
    {
        return redirect()->away($client->createAuthUrl());
    }

    public function callback(Request $request, GoogleClient $client)
    {
        $accessToken = $client->fetchAccessTokenWithAuthCode($request->get('code'));

        $client->setAccessToken($accessToken);

        return redirect()->route('homepage');
    }
}
```

Once a token is stored, resolve any service through the `GoogleApi` facade. If no token is present a `TokenNotFoundException` is thrown carrying the authorization URL, so unauthorized users can be redirected into the OAuth flow:

```
use TomShaw\GoogleApi\GoogleApi;
use TomShaw\GoogleApi\Exceptions\TokenNotFoundException;

try {
    $events = GoogleApi::calendar()->listEvents();
} catch (TokenNotFoundException $e) {
    return redirect()->away($e->authUrl);
}
```

### Access Tokens

[](#access-tokens)

`GoogleClient::getAccessToken()` returns a readonly `TomShaw\GoogleApi\AccessToken` value object (or `null` when no token is stored):

```
$token = $client->getAccessToken();

$token->accessToken;        // string|null
$token->isExpired();        // bool
$token->hasRefreshToken();  // bool
$token->toArray();          // array
```

### Acting on Behalf of a User

[](#acting-on-behalf-of-a-user)

When using a user-scoped storage adapter such as the database adapter, tokens can be read and written for a specific user — useful in queued jobs and console commands where no one is authenticated:

```
use TomShaw\GoogleApi\GoogleApi;

GoogleApi::forUser($user)
    ->gmail()
    ->from('billing@example.com', 'Billing')
    ->to($user->email, $user->name)
    ->subject('Your invoice')
    ->message('Thanks!')
    ->send();
```

### Using Any Google Service

[](#using-any-google-service)

The four bundled adapters cover Calendar, Gmail, Drive, and Books. Any other Google service can be instantiated with the authorized client:

```
use Google\Service\Sheets;
use TomShaw\GoogleApi\GoogleApi;

$sheets = GoogleApi::service(Sheets::class);
```

Storage Adapters
----------------

[](#storage-adapters)

You can provide your own storage mechanism such as file or Redis by setting the `token_storage_adapter` configuration option.

> Storage adapters must implement the `StorageAdapterInterface`. Implement `UserScopedStorageAdapter` as well if your adapter should support `forUser()`.

```
'token_storage_adapter' => TomShaw\GoogleApi\Storage\DatabaseStorageAdapter::class,
```

Two adapters ship with the package:

- `DatabaseStorageAdapter` (default) - persists tokens to the `google_tokens` table keyed by user, with the token columns encrypted at rest. Supports `forUser()`.
- `SessionStorageAdapter` - keeps the token in the current session.

Services Adapters
-----------------

[](#services-adapters)

This package includes example service adapters for Google Calendar, Gmail, Drive, and Books. Each adapter provides a fluent interface for interacting with the respective Google API.

- **[Google Calendar](docs/calendar.md)** - Manage calendar events (create, read, update, delete)
- **[Gmail](docs/gmail.md)** - Send emails with attachments, CC, BCC, and Laravel Mailable support
- **[Google Drive](docs/drive.md)** - List, retrieve, and upload files to Google Drive
- **[Google Books](docs/books.md)** - Search and retrieve book information from Google Books

Changelog
---------

[](#changelog)

For changes made to the project, see the [Changelog](CHANGELOG.md).

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

License
-------

[](#license)

The MIT License (MIT). See [License File](LICENSE) for more information.

###  Health Score

55

—

FairBetter than 97% of packages

Maintenance97

Actively maintained with recent releases

Popularity33

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 91.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~25 days

Recently: every ~17 days

Total

40

Last Release

21d ago

PHP version history (6 changes)v0.1.0PHP ^8.1

v0.1.6PHP ^8.1|^8.2

v0.7.0PHP ^8.1|^8.2|^8.3|^8.4

v0.7.3PHP ^8.2|^8.3|^8.4

v0.11.0PHP ^8.2|^8.3|^8.4|^8.5

v0.12.0PHP ^8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/14fd02efdbaf6247b61c9846697c86dabcbf430374aeff0d80e509d95d186658?d=identicon)[Tom Shaw](/maintainers/Tom%20Shaw)

---

Top Contributors

[![tomshaw](https://avatars.githubusercontent.com/u/32818?v=4)](https://github.com/tomshaw "tomshaw (148 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (12 commits)")[![d8vjork](https://avatars.githubusercontent.com/u/2331052?v=4)](https://github.com/d8vjork "d8vjork (1 commits)")

---

Tags

laravelgooglegoogle apiapi clientgoogle client

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tomshaw-google-api/health.svg)

```
[![Health](https://phpackages.com/badges/tomshaw-google-api/health.svg)](https://phpackages.com/packages/tomshaw-google-api)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M131](/packages/roots-acorn)[flarum/core

Delightfully simple forum software.

201.4M2.3k](/packages/flarum-core)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k15.1M132](/packages/laravel-pulse)[moonshine/moonshine

Laravel administration panel

1.3k253.1k81](/packages/moonshine-moonshine)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M194](/packages/laravel-ai)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
