PHPackages                             yidas/google-apiclient-helper - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. yidas/google-apiclient-helper

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

yidas/google-apiclient-helper
=============================

Google APIs Client Helper - Easy way to accessing Google APIs with PHP

1.1.0(7y ago)1481MITPHPPHP &gt;=5.4

Since Aug 27Pushed 7y ago1 watchersCompare

[ Source](https://github.com/yidas/php-google-api-client-helper)[ Packagist](https://packagist.org/packages/yidas/google-apiclient-helper)[ Docs](https://github.com/yidas/php-google-api-client-helper)[ RSS](/packages/yidas-google-apiclient-helper/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (1)Versions (5)Used By (0)

 [ ![](https://camo.githubusercontent.com/91190ce0c58db36453f3e28ad61e4b643134fd449ba8cec79d38c8f41d501d21/68747470733a2f2f646576656c6f706572732e676f6f676c652e636f6d2f5f7374617469632f326263656431663638662f696d616765732f726564657369676e2d31342f6c6f636b75702d636f6c6f722e706e67) ](https://developers.google.com/products/)

Google API Client Helper
========================

[](#google-api-client-helper)

Google APIs Client Helper - Easy way to accessing Google APIs with PHP

[![Latest Stable Version](https://camo.githubusercontent.com/9604769211f55c61f99d786f38a24bcd34ee1355e8df5614d10b0372ab50ec06/68747470733a2f2f706f7365722e707567782e6f72672f79696461732f676f6f676c652d617069636c69656e742d68656c7065722f762f737461626c653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/yidas/google-apiclient-helper)[![Latest Unstable Version](https://camo.githubusercontent.com/4715a2a63f8daab50ccee0d8e31402780f1ac45a19b3ef706f87ddfbf614cd67/68747470733a2f2f706f7365722e707567782e6f72672f79696461732f676f6f676c652d617069636c69656e742d68656c7065722f762f756e737461626c653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/yidas/google-apiclient-helper)[![License](https://camo.githubusercontent.com/54ebf1154e213636c666f683523b26fdcf9fba9cf2a969ff9dcd64da77aa20ee/68747470733a2f2f706f7365722e707567782e6f72672f79696461732f676f6f676c652d617069636c69656e742d68656c7065722f6c6963656e73653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/yidas/google-apiclient-helper)

FEATURES
--------

[](#features)

- *Easy way to develop and manage Google API application*
- *Documentation supported for Service SDK*
- *Simple usage for each Service*

This Helper is based on [google-api-php-client](https://github.com/google/google-api-php-client) and [google-api-php-client-services](https://github.com/google/google-api-php-client-services).

---

OUTLINE
-------

[](#outline)

- [Demonstration](#demonstration)
- [Requirements](#requirements)
- [Installation](#installation)
- [Google Client](#google-client)
    - [Configuration](#configuration)
        - [Config Array Method](#config-array-method)
        - [Config Chain Method](#config-chain-method)
        - [Encapsulating Method](#encapsulating-method)
    - [AccessToken Usage](#accesstoken-usage)
        - [refreshAccessToken()](#refreshaccesstoken)
        - [verifyAccessToken()](#verifyaccesstoken)
        - [verifyScopes()](#verifyscopes)
    - [Implementation](#implementation)
- [Google Services](#google-services)
    - [People](#people)
        - [Attributes](#attributes)
        - [getSimpleContacts()](#getsimplecontacts)
        - [createContact()](#createcontact)
        - [updateContact()](#updatecontact)
        - [deleteContact()](#deletecontact)
- [Exceptions](#exceptions)
- [Reference](#reference)

---

DEMONSTRATION
-------------

[](#demonstration)

```
$client = \yidas\google\apiHelper\Client::setClient()
    ->setApplicationName('Google API')
    ->setAuthConfig('/path/google_api_secret.json')
    ->setRedirectUri("http://{$_SERVER['HTTP_HOST']}" . dirname($_SERVER['PHP_SELF'])
    ->setAccessToken($accessToken)
    ->getClient();

if ($accessToken = ClientHelper::refreshAccessToken()) {
    // saveAccessToken($accessToken)
}

// People Service uses Google_Client from Client helper above
$contacts = \yidas\google\apiHelper\services\People::getSimpleContacts();
```

---

REQUIREMENTS
------------

[](#requirements)

This library requires the following:

- PHP 5.4.0+
- google/apiclient 2.0+

---

INSTALLATION
------------

[](#installation)

Run Composer in your project:

```
composer require yidas/google-apiclient-helper

```

Then you could call it after Composer is loaded depended on your PHP framework:

```
require __DIR__ . '/vendor/autoload.php';

use yidas\google\apiHelper\Client;
```

---

GOOGLE CLIENT
-------------

[](#google-client)

### Configuration

[](#configuration)

There are many way to set `Google_Client` by Helper:

#### Config Array Method

[](#config-array-method)

The config keys refer to the methods of `Google_Client`. For exmaple, `authConfig` refers to `Google_Client->setAuthConfig()`.

```
$client = \yidas\google\apiHelper\Client::setClient([
        'applicationName' => 'Google API',
        'authConfig' => '/path/google_api_secret.json',
        'redirectUri' => "http://{$_SERVER['HTTP_HOST']}" . dirname($_SERVER['PHP_SELF'],
        ])
    ->getClient();
```

#### Config Chain Method

[](#config-chain-method)

The methods refer to the same method names of `Google_Client`. For exmaple, `setAuthConfig()` refers to `Google_Client->setAuthConfig()`.

```
$client = \yidas\google\apiHelper\Client::setClient()
    ->setApplicationName('Google API')
    ->setAuthConfig('/path/google_api_secret.json')
    ->setRedirectUri("http://{$_SERVER['HTTP_HOST']}" . dirname($_SERVER['PHP_SELF'])
    ->getClient();
```

#### Encapsulating Method

[](#encapsulating-method)

```
$client = new Google_Client();
$client->setAuthConfig('/path/google_api_secret.json');
\yidas\google\apiHelper\Client::setClient($client);
```

> After encapsulating Google\_Client into Helper, the Helper would share with the same Google\_Client object.

### AccessToken Usage

[](#accesstoken-usage)

#### refreshAccessToken()

[](#refreshaccesstoken)

Simple way to get refreshed access token or false expired to skip

```
public static array|false refreshAccessToken()
```

*Example:*

```
$client = \yidas\google\apiHelper\Client::setClient()
    ->setApplicationName('Google API')
    ->setAuthConfig('/path/google_api_secret.json')
    ->setRedirectUri("http://{$_SERVER['HTTP_HOST']}" . dirname($_SERVER['PHP_SELF'])
    ->setAccessToken($accessToken)
    ->getClient();

// Simple way to get refreshed access token or false expired to skip
if ($accessToken = ClientHelper::refreshAccessToken()) {
    // saveAccessToken($accessToken)
}
```

> Helper handles the setting `setAccessType('offline')` &amp; `setApprovalPrompt('force')` for refresh token.

#### verifyAccessToken()

[](#verifyaccesstoken)

Verify an access\_token. This method will verify the current access\_token by Google API, if one isn't provided.

```
public static array|false verifyAccessToken(string $accessToken=null)
```

#### verifyScopes()

[](#verifyscopes)

Verify scopes of tokenInfo by access\_token. This method will verify the current access\_token by Google API, if one isn't provided.

```
public static array|false verifyScopes(array $scopes, string $accessToken=null)
```

*Example:*

```
$result = \yidas\google\apiHelper\Client::verifyScopes([
    'https://www.googleapis.com/auth/userinfo.profile',
]);
```

### Implementation

[](#implementation)

There are more implementations such as `addScope()` or `createAuthUrl()` for OAuth register, you cloud refer following sample code:

[yidas/php-google-api-sample](https://github.com/yidas/php-google-api-sample)

---

GOOGLE SERVICES
---------------

[](#google-services)

You could directly use any Service Helpers which uses `Google_Client` from `yidas\google\apiHelper\Client`:

```
use \yidas\google\apiHelper\services\People as PeopleHelper;
\yidas\google\apiHelper\Client::setClient([...])

$contacts = PeopleHelper::getSimpleContacts();
```

Or you could reset a `Google_Client` for each Service Helper:

```
use \yidas\google\apiHelper\services\People as PeopleHelper;

PeopleHelper::setClient($googleClient);
// PeopleHelper::method()...
```

Use `getService()` to get back current Google Service object for advanced usage:

```
$service = \yidas\google\apiHelper\services\People::getService();
// $service->people_connections->...
```

### People

[](#people)

*API Document: *

People helper has smart call refered to [Google\_Service\_PeopleService\_Person](https://github.com/google/google-api-php-client-services/blob/master/src/Google/Service/PeopleService/Person.php) methods, which provides easy interface to `setValue()` for a person.

```
// Simple setValue() example
\yidas\google\apiHelper\services\People::newPerson
    ->setEmailAddresses('myintaer@gmail.com')
    ->setPhoneNumbers('+886')
    ->setBiographies("I'm a note");
```

#### Attributes

[](#attributes)

It's easy to set attributes for a person by Helper, which provides three types for input data:

##### 1. Origin Object

[](#1-origin-object)

Input by original Google Attribute Classes that are not so convenience.

```
$gPhoneNumber = new Google_Service_PeopleService_PhoneNumber;
$gPhoneNumber->setValue('+886');
\yidas\google\apiHelper\services\People::setPhoneNumbers($gPhoneNumber);
```

##### 2. Array

[](#2-array)

Input by array type would map to the API key-value setting.

```
\yidas\google\apiHelper\services\People::setPhoneNumbers(['value' => '+886']);
```

##### 3. String

[](#3-string)

Input by string type would enable Helper attribute handler which automatically settles value for all attributes.

```
\yidas\google\apiHelper\services\People::setPhoneNumbers('+886');
```

#### getSimpleContacts()

[](#getsimplecontacts)

Get simple contact data with parser

```
public static array getContacts()
```

*Example:*

```
// Get formated list by Helper
$contacts = \yidas\google\apiHelper\services\People::getSimpleContacts();
```

Result:

```
Array
(
    [0] => Array
        (
            [id] => people/c26081557840316580
            [name] => Mr.Nick
            [email] =>
            [phone] => 0912 345 678
        )
    ...
```

> This is simple fields parser, you could use `listPeopleConnections()` if you need all fields.

#### createContact()

[](#createcontact)

Create a People Contact

```
public static Google_Service_PeopleService_Person createContact()
```

*Example:*

```
$person = \yidas\google\apiHelper\services\People::newPerson()
    ->setNames('Nick')
    ->setEmailAddresses('myintaer@gmail.com')
    ->setPhoneNumbers('+886')
    ->createContact();
```

> Resource Name: `$person->resourceName` or `$person['resourceName']`.

#### updateContact()

[](#updatecontact)

Update a People Contact

```
public static Google_Service_PeopleService_PeopleEmpty updateContact(array $optParams=null)
```

*Example:*

```
$person = \yidas\google\apiHelper\services\People::findByResource($resourceName)
    ->setNames('Nick')
    ->setEmailAddresses('myintaer@gmail.com')
    ->setPhoneNumbers('+886')
    ->updateContact();
```

#### deleteContact

[](#deletecontact)

Delete a People Contact

```
public static Google_Service_PeopleService_PeopleEmpty deleteContact(string $resourceName=null, array $optParams=[])
```

*Example:*

```
$person = \yidas\google\apiHelper\services\People::deleteContact($resourceName);
```

You could also use find pattern:

```
$person = \yidas\google\apiHelper\services\People::findByResource($resourceName)
    ->deleteContact();
```

---

EXCEPTIONS
----------

[](#exceptions)

For all Google Exception including Client and Services:

```
try {} catch (\Google_Exception $e) {}
```

Otherwise, for Google Services only:

```
try {} catch (\Google_Service_Exception $e) {}
```

---

REFERENCE
---------

[](#reference)

- [Google API PHP Client SDK](https://github.com/google/google-api-php-client)
- [Google API PHP Client Serivces SDK](https://github.com/google/google-api-php-client-services)
- [Google Identity Platform](https://developers.google.com/identity/)
- [Google People API](https://developers.google.com/people/)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

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

Total

4

Last Release

2796d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b30d2b2c0b53aef65fad4af56cd3c7912d3db2b612890c706fe79448717f6aba?d=identicon)[yidas](/maintainers/yidas)

---

Top Contributors

[![yidas](https://avatars.githubusercontent.com/u/12604195?v=4)](https://github.com/yidas "yidas (9 commits)")

---

Tags

helpergoogle apiphp-sdkgoogle api client

### Embed Badge

![Health badge](/badges/yidas-google-apiclient-helper/health.svg)

```
[![Health](https://phpackages.com/badges/yidas-google-apiclient-helper/health.svg)](https://phpackages.com/packages/yidas-google-apiclient-helper)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[bryanjhv/slim-session

Session middleware and helper for Slim framework 4.

233961.5k16](/packages/bryanjhv-slim-session)[laravelista/ekko

Framework agnostic PHP package for marking navigation items active.

278673.4k4](/packages/laravelista-ekko)[beste/json

A simple JSON helper to decode and encode JSON

4222.7M3](/packages/beste-json)[chillerlan/php-settings-container

A container class for immutable settings objects. Not a DI container.

3427.3M21](/packages/chillerlan-php-settings-container)[kartik-v/yii2-helpers

A collection of useful helper functions for Yii Framework 2.0

883.0M29](/packages/kartik-v-yii2-helpers)

PHPackages © 2026

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