Skip to content

Google api php client wrapper with Cloud Platform and Laravel support

License

Notifications You must be signed in to change notification settings

hieunhit/google-apiclient

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Google Api Client Wrapper

Google api php client wrapper with Cloud Platform and Laravel support

Build Status Scrutinizer Code Quality Coverage Status License Latest Version Total Downloads

Requirements

This package requires PHP >=5.4

Installation

Install via composer - edit your composer.json to require the package.

"require": {
    "pulkitjalan/google-apiclient": "dev-master"
}

Then run composer update in your terminal to pull it in.

Laravel

To use in laravel add the following to the providers array in your config/app.php

'PulkitJalan\Google\GoogleServiceProvider'

Next add the following to the aliases array in your config/app.php

'Google' => 'PulkitJalan\Google\Facades\Google'

Finally run php artisan config:publish pulkitjalan/google-apiclient to publish the config file.

Usage

The Client class takes an array as the first parameter, see example of config file below:

return [
    /*
    |----------------------------------------------------------------------------
    | Google application name
    |----------------------------------------------------------------------------
    */
    'application_name' => '',

    /*
    |----------------------------------------------------------------------------
    | Google OAuth 2.0 access
    |----------------------------------------------------------------------------
    |
    | Keys for OAuth 2.0 access, see the API console at
    | https://developers.google.com/console
    |
    */
    'client_id' => '',
    'client_secret' => '',
    'redirect_uri' => '',
    'scopes' => [],
    'access_type' => 'online',
    'approval_prompt' => 'auto',

    /*
    |----------------------------------------------------------------------------
    | Google developer key
    |----------------------------------------------------------------------------
    |
    | Simple API access key, also from the API console. Ensure you get
    | a Server key, and not a Browser key.
    |
    */
    'developer_key' => '',

    /*
    |----------------------------------------------------------------------------
    | Google service account
    |----------------------------------------------------------------------------
    |
    | Set the information below to use assert credentials
    | Leave blank to use app engine or compute engine.
    |
    */
    'service' => [
        /*
        | Example xxx@developer.gserviceaccount.com
        */
        'account' => '',

        /*
        | Example ['https://www.googleapis.com/auth/cloud-platform']
        */
        'scopes' => [],

        /*
        | Path to key file
        | Example storage_path().'/key/google.p12'
        */
        'key' => '',
    ]
];

To use the Google Cloud Platform Services you can either set the information in the config file under service, or if running under compute engine (or app engine) leave it blank.

NOTE: service => ['account'] is the service Email Address and not the Client ID!

Get Google_Client

$client = new PulkitJalan\Google\Client($config);
$googleClient = $client->getClient();

Laravel Example:

$googleClient = Google::getClient();

Get a service

$client = new PulkitJalan\Google\Client($config);

// returns instance of \Google_Service_Storage
$storage = $client->make('storage');

// list buckets example
$storage->buckets->listBuckets('project id');

// get object example
$storage->objects->get('bucket', 'object');

About

Google api php client wrapper with Cloud Platform and Laravel support

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%