PHPackages                             alxmsl/googleclient - 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. alxmsl/googleclient

ActiveLibrary

alxmsl/googleclient
===================

Google services API library

v2.1.0(10y ago)51.2k6[3 issues](https://github.com/alxmsl/GoogleClient/issues)[1 PRs](https://github.com/alxmsl/GoogleClient/pulls)Apache-2.0PHPCI passing

Since Jul 19Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/alxmsl/GoogleClient)[ Packagist](https://packagist.org/packages/alxmsl/googleclient)[ RSS](/packages/alxmsl-googleclient/feed)WikiDiscussions master Synced 1w ago

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

GoogleClient
============

[](#googleclient)

[![License](https://camo.githubusercontent.com/a549a7a30bacba7bfceebdc207a8e86c3f2c02995a2527640dca30048fd2b64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d417061636865253230322e302d626c75652e737667)](http://www.apache.org/licenses/LICENSE-2.0)[![Build Status](https://camo.githubusercontent.com/0920a9786953fc5dee2486bfeeaa3b8e680e67f2de610212c04ab1a503266c0f/68747470733a2f2f7472617669732d63692e6f72672f616c786d736c2f476f6f676c65436c69656e742e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/alxmsl/GoogleClient)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/9b670344d81594a32b19133bcd5c65ec96eb6a4d2a11b326dd834787bc497018/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f616c786d736c2f476f6f676c65436c69656e742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/alxmsl/GoogleClient/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/7cfd90df7401df64c949702d4e3477edd5388f7ac5c2942fcc67cb8b591fb92c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f616c786d736c2f476f6f676c65436c69656e742f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/alxmsl/GoogleClient/?branch=master)

Google services API library. Supported APIs:

- [OAuth2 authorization API](/README.md#oauth2)
- [Google Cloud Messaging API](/README.md#gcm)
- Android Publisher API: [in-app products](/README.md#inapp), [purchases products](/README.md#products) and [purchases subscriptions](/README.md#subscriptions)

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

[](#installation)

For install library you need to modify your composer configuration file

```
    "alxmsl/googleclient": "*"

```

And just run installation command

```
    $ composer.phar install

```

 OAuth2 authorization
-------------------------------------------------------

[](#-oauth2-authorization)

To authorize client via [Google OAuth2](https://developers.google.com/android-publisher/authorization) you need to create [WebServerApplication](/source/OAuth2/WebServerApplication.php) instance with needed scopes using client identifier, client secret and redirect uri from you console

```
    $Client = new WebServerApplication();
    $Client->setClientId()
        ->setClientSecret()
        ->setRedirectUri();

```

...make authentication url

```
    $Client->createAuthUrl([
            'https://www.googleapis.com/auth/androidpublisher',
        ]
        , ''
        , WebServerApplication::RESPONSE_TYPE_CODE
        , WebServerApplication::ACCESS_TYPE_OFFLINE
        , WebServerApplication::APPROVAL_PROMPT_FORCE);

```

...compete authorization in browser and give authorization code. With this code you could get access token

```
    $Token = $Client->authorizeByCode();
    print((string) $Token);

```

You could see examples [webclient.uri.php](/examples/webclient.uri.php) about uri creation, and [webclient.authorize.php](/examples/webclient.authorize.php) about code authentication. Already you could use completed script [authorize.php](/bin/authorize.php)

```
$ php bin/authorize.php
Using: /usr/local/bin/php bin/authorize.php [-h|--help] [-o|--code] -c|--client -r|--redirect -s|--scopes -e|--secret
-h, --help  - show help
-o, --code  - authorization code
-c, --client  - client id
-r, --redirect  - redirect uri
-s, --scopes  - grant scopes
-e, --secret  - client secret

$ php bin/authorize.php --client='my-client@id' --secret='clientsecret' --redirect='http://example.com/oauth2callback'
    --scopes='https://www.googleapis.com/auth/androidpublisher'
https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=my-client@id
&redirect_uri=http%3A%2F%2Fexample.com%2Foauth2callback&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fandroidpublisher
&access_type=offline&approval_prompt=force

$ php bin/authorize.php --client='my-client@id' --secret='clientsecret' --code='authorization/code'
    access token:  ya.AccES5_T0keN
    expires in:    3558
    id token:      id.T0kEn
    refresh token: refrE5H_T0KEN
    token type:    Bearer

```

Of course, I created scripts for token refreshing

```
$ php bin/refresh.php
Using: /usr/local/bin/php bin/refresh.php [-h|--help] -c|--client -e|--secret -t|--token
-h, --help  - show help
-c, --client  - client id
-e, --secret  - client secret
-t, --token  - refresh token

```

...and token revoking

```
$ php bin/revoke.php --help
Using: /usr/local/bin/php bin/revoke.php [-h|--help] -t|--token
-h, --help  - show help
-t, --token  - revoked token

```

 Google Cloud Messaging
------------------------------------------------------

[](#-google-cloud-messaging)

For create [Google Cloud Message](https://developer.android.com/google/gcm/index.html) you need to create child for class [PayloadData](/source/GCM/Message/PayloadData.php) and define `getDataFields` method. You could see example below or in [gcm.php](/examples/gcm.php)

```
    // Create payload data class
    final class NewPayloadData extends PayloadData {
        protected function getDataFields() {
            return [
                'test' => 'test_01',
            ];
        }
    }

    // Create and initialize payload message instance
    $Message = new PayloadMessage();
    $Message->setRegistrationIds('DeV1CeT0kEN')
        ->setType(PayloadMessage::TYPE_JSON)
        ->setData(new NewPayloadData());

    // Create GCM client
    $Client = new Client();
    $Client->getRequest()->setConnectTimeout(60)
        ->setSslVersion(6);
    $Client->setAuthorizationKey('aUTH0R1Z4t1oNKEy');

    // ...and send the message
    $Response = $Client->send($Message);
    var_dump($Response);

```

You could use [completed script](/bin/gcm.php)

```
$ php bin/gcm.php
Using: /usr/local/bin/php bin/gcm.php [-h|--help] [-d|--data] -i|--id -k|--key
-h, --help  - show help
-d, --data  - payload data
-i, --id  - device registration id
-k, --key  - authorization key

$ php bin/gcm.php --id='DeV1CeT0kEN' --key='aUTH0R1Z4t1oNKEy' --data='{"test":"test_01"}'
    success: 1
    failure: 0

```

 In-app purchases
--------------------------------------------------

[](#-in-app-purchases)

You could use [In-App products API](https://developers.google.com/android-publisher/api-ref/inappproducts) to manage products of your application. For example, you could get all product prices for all end-user countries

```
    $Client = new Client();
    $Client->setPackage()
        ->setAccessToken();
    /** @var InAppProductsResource $Resource */
    $Resource = $Client->get();
    var_dump($Resource->getPrices());

```

Already, you could use [inappproducts.get.php](/bin/inappproducts.get.php) to get info about products

```
$ php bin/inappproducts.get.php --help
Using: /usr/local/bin/php bin/inappproducts.get.php [-h|--help] -a|--access [-p|--package] -r|--product
-h, --help  - show help
-a, --access  - access token
-p, --package  - package name
-r, --product  - product id

```

 Purchases products
-------------------------------------------------------

[](#-purchases-products)

Using Purchases.Products API you could check user purchases in third-party server application. For example if purchase purchased and does not cancel now:

```
    use alxmsl\Google\AndroidPublisher\Purchases\Client;
    use alxmsl\Google\AndroidPublisher\Purchases\Products\Resource as ProductsResource;

    $Client = new Client();
    $Client->setPackage()
        ->setAccessToken();

    /** @var ProductsResource $Resource */
    $Resource = $Client->get(, );
    var_dump($Resource->isPurchased() && !$Resource->isCancelled());

```

 Purchases subscriptions
-----------------------------------------------------------------

[](#-purchases-subscriptions)

This library allows all operations over user [subscriptions](https://developers.google.com/android-publisher/api-ref/purchases/subscriptions) using some scripts: [get](/bin/subscriptions.get.php), [cancel](/bin/subscriptions.cancel.php), [defer](/bin/subscriptions.defer.php), [refund](/bin/subscriptions.refund.php) and [revoke](/bin/subscriptions.revoke.php)

How to check subscription, for example:

```
    use alxmsl\Google\AndroidPublisher\Purchases\Subscription\Resource as SubscriptionsResource;
    use alxmsl\Google\AndroidPublisher\Purchases\Subscription\SubscriptionsClient;

    $Client = new SubscriptionsClient();
    $Client->setPackage()
        ->setAccessToken();

    /** @var SubscriptionsResource $Resource */
    $Resource = $Client->get(, );
    var_dump($Resource->isAutoRenewing() && !$Resource->isExpired());

```

Tests
-----

[](#tests)

For completely tests running just call `phpunit` command

```
    $ phpunit
    PHPUnit 4.7.3 by Sebastian Bergmann and contributors.

    ..........................................

    Time: 118 ms, Memory: 7.25Mb

    OK (42 tests, 365 assertions)

```

License
-------

[](#license)

Copyright 2015 Alexey Maslov

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

```
http://www.apache.org/licenses/LICENSE-2.0

```

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance49

Moderate activity, may be stable

Popularity23

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 98.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 ~39 days

Recently: every ~87 days

Total

18

Last Release

3654d ago

Major Versions

v1.3.5 → v2.0.02015-06-17

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/950057?v=4)[Alexey Maslov](/maintainers/alxmsl)[@alxmsl](https://github.com/alxmsl)

---

Top Contributors

[![alxmsl](https://avatars.githubusercontent.com/u/950057?v=4)](https://github.com/alxmsl "alxmsl (94 commits)")[![chapsuk](https://avatars.githubusercontent.com/u/5525114?v=4)](https://github.com/chapsuk "chapsuk (1 commits)")

---

Tags

googlegcmapisinapp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/alxmsl-googleclient/health.svg)

```
[![Health](https://phpackages.com/badges/alxmsl-googleclient/health.svg)](https://phpackages.com/packages/alxmsl-googleclient)
```

###  Alternatives

[google/apiclient

Client library for Google APIs

9.8k191.4M997](/packages/google-apiclient)[google/auth

Google Auth Library for PHP

1.4k272.7M162](/packages/google-auth)[google/apiclient-services

Client library for Google APIs

1.3k180.5M51](/packages/google-apiclient-services)[kreait/firebase-php

Firebase Admin SDK

2.4k39.7M72](/packages/kreait-firebase-php)[kreait/laravel-firebase

A Laravel package for the Firebase PHP Admin SDK

1.3k16.5M42](/packages/kreait-laravel-firebase)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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