PHPackages                             keboola/google-client-bundle - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. keboola/google-client-bundle

ActiveLibrary[HTTP &amp; Networking](/categories/http)

keboola/google-client-bundle
============================

Keboola Google API Client

6.0.1(9mo ago)03.4k1MITPHPPHP ^8.1CI passing

Since Jun 24Pushed 9mo ago14 watchersCompare

[ Source](https://github.com/keboola/google-client-bundle)[ Packagist](https://packagist.org/packages/keboola/google-client-bundle)[ RSS](/packages/keboola-google-client-bundle/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (7)Versions (50)Used By (1)

Keboola Google Client Bundle
============================

[](#keboola-google-client-bundle)

Keboola Google API Client with OAuth 2.0 and Service Account authentication support.

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

[](#installation)

```
composer require keboola/google-client-bundle
```

Usage
-----

[](#usage)

This library supports two types of authentication:

1. **OAuth 2.0** - for applications that need access to user data
2. **Service Account** - for server-to-server communication without user intervention

### OAuth 2.0 Authentication

[](#oauth-20-authentication)

#### Classic approach

[](#classic-approach)

```
use Keboola\Google\ClientBundle\Google\RestApi;

$api = new RestApi($logger); // Optional logger parameter
$api->setAppCredentials($clientId, $clientSecret);
$api->setCredentials($accessToken, $refreshToken);

// Get authorization URL
$authUrl = $api->getAuthorizationUrl(
    'http://localhost/callback',
    'https://www.googleapis.com/auth/drive.readonly',
    'force',
    'offline'
);

// Authorize using code
$tokens = $api->authorize($code, 'http://localhost/callback');

// API calls
$response = $api->request('/drive/v2/files');
```

#### New factory approach

[](#new-factory-approach)

```
use Keboola\Google\ClientBundle\Google\RestApi;

$api = RestApi::createWithOAuth(
    $clientId,
    $clientSecret,
    $accessToken,
    $refreshToken
);

// Usage same as above
$response = $api->request('/drive/v2/files');
```

### Service Account Authentication

[](#service-account-authentication)

```
use Keboola\Google\ClientBundle\Google\RestApi;

// Service account JSON configuration (from Google Cloud Console)
$serviceAccountConfig = [
    'type' => 'service_account',
    'project_id' => 'your-project-id',
    'private_key_id' => 'key-id',
    'private_key' => '-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n',
    'client_email' => 'your-service-account@your-project.iam.gserviceaccount.com',
    'client_id' => '123456789',
    'auth_uri' => 'https://accounts.google.com/o/oauth2/auth',
    'token_uri' => 'https://oauth2.googleapis.com/token',
    'auth_provider_x509_cert_url' => 'https://www.googleapis.com/oauth2/v1/certs',
    'client_x509_cert_url' => 'https://www.googleapis.com/robot/v1/metadata/x509/your-service-account%40your-project.iam.gserviceaccount.com'
];

// Scope definitions
$scopes = [
    'https://www.googleapis.com/auth/cloud-platform',
    'https://www.googleapis.com/auth/drive.readonly'
];

// Create API client
$api = RestApi::createWithServiceAccount(
    $serviceAccountConfig,
    $scopes
);

// API calls
$response = $api->request('/drive/v2/files');
```

#### Loading Service Account from JSON file

[](#loading-service-account-from-json-file)

```
use Keboola\Google\ClientBundle\Google\RestApi;

// Load from JSON file
$serviceAccountConfig = json_decode(
    file_get_contents('/path/to/service-account-key.json'),
    true
);

$scopes = ['https://www.googleapis.com/auth/cloud-platform'];

$api = RestApi::createWithServiceAccount($serviceAccountConfig, $scopes);
$response = $api->request('/your-api-endpoint');
```

Differences between OAuth and Service Account
---------------------------------------------

[](#differences-between-oauth-and-service-account)

PropertyOAuth 2.0Service AccountAuthentication typeUser-basedServer-to-serverRefresh token✅ Yes❌ No (not needed)AuthorizationRequires user consentAutomaticUsageAccess to user dataAccess to application dataToken expirationBased on refresh tokenAutomatic renewalAdvanced Usage
--------------

[](#advanced-usage)

### Retry and Backoff

[](#retry-and-backoff)

```
$api->setBackoffsCount(10); // Number of retries
$api->setDelayFn(function($retries) {
    return 1000 * pow(2, $retries); // Exponential backoff
});
```

### Logging

[](#logging)

```
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$logger = new Logger('google-api');
$logger->pushHandler(new StreamHandler('php://stdout'));

$api = RestApi::createWithServiceAccount(
    $serviceAccountConfig,
    $scopes,
    $logger
);
```

### Custom HTTP Options

[](#custom-http-options)

```
$response = $api->request('/endpoint', 'POST', [
    'Content-Type' => 'application/json'
], [
    'json' => ['key' => 'value'],
    'timeout' => 30
]);
```

Testing
-------

[](#testing)

```
# OAuth tests (require environment variables)
export CLIENT_ID="your-client-id"
export CLIENT_SECRET="your-client-secret"
export REFRESH_TOKEN="your-refresh-token"

# Service Account tests (optional)
export SERVICE_ACCOUNT_JSON='{"type":"service_account","project_id":"your-project",...}'

# Run tests
composer tests
```

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

[](#requirements)

- PHP ^7.1
- guzzlehttp/guzzle ^6.0
- google/auth ^1.26

License
-------

[](#license)

MIT

###  Health Score

48

—

FairBetter than 95% of packages

Maintenance56

Moderate activity, may be stable

Popularity19

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity85

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 56% 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 ~100 days

Recently: every ~180 days

Total

45

Last Release

293d ago

Major Versions

1.1.7 → 2.0.02014-11-11

2.0.6 → 3.0.02015-10-30

3.0.3 → 4.0.02016-01-19

4.6.0 → 5.0.02019-01-11

5.5.0 → 6.0.02025-07-29

PHP version history (4 changes)1.0.0PHP &gt;=5.3.5

2.0.0PHP &gt;=5.4.0

5.0.0PHP ^7.1

5.5.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/101dbf2551a0709ddab522f97669f13a2c4cc2d0a1e8d009f3af6ba80accb1a9?d=identicon)[Keboola](/maintainers/Keboola)

---

Top Contributors

[![MiroCillik](https://avatars.githubusercontent.com/u/1488015?v=4)](https://github.com/MiroCillik "MiroCillik (47 commits)")[![AdamVyborny](https://avatars.githubusercontent.com/u/27994036?v=4)](https://github.com/AdamVyborny "AdamVyborny (20 commits)")[![ondrajodas](https://avatars.githubusercontent.com/u/12143866?v=4)](https://github.com/ondrajodas "ondrajodas (15 commits)")[![ujovlado](https://avatars.githubusercontent.com/u/419849?v=4)](https://github.com/ujovlado "ujovlado (2 commits)")

---

Tags

clientrestgooglekeboola

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/keboola-google-client-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/keboola-google-client-bundle/health.svg)](https://phpackages.com/packages/keboola-google-client-bundle)
```

###  Alternatives

[akamai-open/edgegrid-client

Implements the Akamai {OPEN} EdgeGrid Authentication specified by https://developer.akamai.com/introduction/Client\_Auth.html

482.5M6](/packages/akamai-open-edgegrid-client)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69114.3k](/packages/serpapi-google-search-results-php)[cybercog/youtrack-rest-php

YouTrack REST API PHP Client.

37149.2k3](/packages/cybercog-youtrack-rest-php)[huaweicloud/huaweicloud-sdk-php

Huawei Cloud SDK for PHP

1829.2k2](/packages/huaweicloud-huaweicloud-sdk-php)[pdffiller/pdffiller-php-api-client

PHP client for pdffiller.com REST API

14140.2k](/packages/pdffiller-pdffiller-php-api-client)[meteocontrol/vcom-api-client

HTTP Client for meteocontrol's VCOM API - The VCOM API enables you to directly access your data on the meteocontrol platform.

175.7k1](/packages/meteocontrol-vcom-api-client)

PHPackages © 2026

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