2017 © Pedro Peláez
 

library googleclient

Google services API library

image

alxmsl/googleclient

Google services API library

  • Monday, May 16, 2016
  • by alxmsl
  • Repository
  • 1 Watchers
  • 3 Stars
  • 331 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 2 Open issues
  • 19 Versions
  • 2 % Grown

The README.md

GoogleClient

License Build Status Scrutinizer Code Quality Code Coverage, (*1)

Google services API library. Supported APIs:, (*2)

Installation

For install library you need to modify your composer configuration file, (*3)

    "alxmsl/googleclient": "*"

And just run installation command, (*4)

    $ composer.phar install

OAuth2 authorization

To authorize client via Google OAuth2 you need to create WebServerApplication instance with needed scopes using client identifier, client secret and redirect uri from you console, (*5)

    $Client = new WebServerApplication();
    $Client->setClientId(<client id>)
        ->setClientSecret(<client secret>)
        ->setRedirectUri(<redirect uri>);

...make authentication url, (*6)

    $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, (*7)

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

You could see examples webclient.uri.php about uri creation, and webclient.authorize.php about code authentication. Already you could use completed script authorize.php, (*8)

$ 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, (*9)

$ 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, (*10)

$ 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

For create Google Cloud Message you need to create child for class PayloadData and define getDataFields method. You could see example below or in gcm.php, (*11)

    // 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, (*12)

$ 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

You could use In-App products API to manage products of your application. For example, you could get all product prices for all end-user countries, (*13)

    $Client = new Client();
    $Client->setPackage(<package name>)
        ->setAccessToken(<access token>);
    /** @var InAppProductsResource $Resource */
    $Resource = $Client->get(<product id>);
    var_dump($Resource->getPrices());

Already, you could use inappproducts.get.php to get info about products, (*14)

$ 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

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

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

    $Client = new Client();
    $Client->setPackage(<package name>)
        ->setAccessToken(<access token>);

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

Purchases subscriptions

This library allows all operations over user subscriptions using some scripts: get, cancel, defer, refund and revoke, (*16)

How to check subscription, for example:, (*17)

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

    $Client = new SubscriptionsClient();
    $Client->setPackage(<package name>)
        ->setAccessToken(<access token>);

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

Tests

For completely tests running just call phpunit command, (*18)

    $ phpunit
    PHPUnit 4.7.3 by Sebastian Bergmann and contributors.

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

    Time: 118 ms, Memory: 7.25Mb

    OK (42 tests, 365 assertions)

License

Copyright 2015 Alexey Maslov alexey.y.maslov@gmail.com, (*19)

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, (*20)

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., (*21)

The Versions

16/05 2016

dev-master

9999999-dev

Google services API library

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar alxmsl

google gcm inapp apis

16/05 2016

v2.1.0

2.1.0.0

Google services API library

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar alxmsl

google gcm inapp apis

03/02 2016

v2.0.2

2.0.2.0

Google services API library

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar alxmsl

google gcm inapp apis

06/08 2015

v2.0.1

2.0.1.0

Google services API library

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar alxmsl

google gcm inapp apis

18/06 2015

v2.0.0

2.0.0.0

Google services API library

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar alxmsl

google gcm inapp apis

03/06 2015

v1.3.5

1.3.5.0

Google services API library

  Sources   Download

WTFPL

The Requires

 

The Development Requires

by Avatar alxmsl

google gcm inapp apis

03/06 2015

v1.3.4

1.3.4.0

Google services API library

  Sources   Download

WTFPL

The Requires

 

The Development Requires

by Avatar alxmsl

google gcm inapp apis

03/06 2015

v1.3.3

1.3.3.0

Google services API library

  Sources   Download

WTFPL

The Requires

 

The Development Requires

by Avatar alxmsl

google gcm inapp apis

28/05 2015

v1.3.2

1.3.2.0

Google services API library

  Sources   Download

WTFPL

The Requires

 

The Development Requires

by Avatar alxmsl

google gcm inapp apis

27/05 2015

v1.3.1

1.3.1.0

Google services API library

  Sources   Download

WTFPL

The Requires

 

by Avatar alxmsl

google gcm inapp apis

24/05 2015

v1.3.0

1.3.0.0

Google services API library

  Sources   Download

WTFPL

The Requires

 

by Avatar alxmsl

google gcm inapp apis

18/05 2015

v1.2.4

1.2.4.0

Google services API library

  Sources   Download

WTFPL

The Requires

 

by Avatar alxmsl

google gcm inapp apis

18/05 2015

v1.2.3

1.2.3.0

Google services API library

  Sources   Download

WTFPL

The Requires

 

by Avatar alxmsl

google gcm inapp apis

18/05 2015

v1.2.2

1.2.2.0

Google services API library

  Sources   Download

WTFPL

The Requires

 

by Avatar alxmsl

google gcm inapp apis

19/04 2015

v1.2.1

1.2.1.0

Google services API library

  Sources   Download

WTFPL

The Requires

 

by Avatar alxmsl

google gcm inapp apis

16/04 2015

v1.2.0

1.2.0.0

Google services API library

  Sources   Download

WTFPL

The Requires

 

by Avatar alxmsl

google gcm inapp apis

25/02 2015

v1.1.1

1.1.1.0

Google services API library

  Sources   Download

WTFPL

The Requires

 

by Avatar alxmsl

google gcm inapp apis

25/02 2015

v1.1.0

1.1.0.0

Google services API library

  Sources   Download

WTFPL

The Requires

 

by Avatar alxmsl

google gcm inapp apis

19/07 2014

v1.0.0

1.0.0.0

Google services API library

  Sources   Download

WTFPL

The Requires

 

by Avatar alxmsl