|
1 | | -# laravel-google-api-client |
2 | | -(WIP) Laravel wrapper for the Google api php client |
| 1 | +Google Api Client Wrapper |
| 2 | +========= |
| 3 | + |
| 4 | +> Google api php client wrapper with Cloud Platform and Laravel support |
| 5 | +
|
| 6 | +[](https://travis-ci.org/pulkitjalan/google-apiclient) |
| 7 | +[](https://scrutinizer-ci.com/g/pulkitjalan/google-apiclient/) |
| 8 | +[](https://scrutinizer-ci.com/g/pulkitjalan/google-apiclient/code-structure/master) |
| 9 | +[](http://www.opensource.org/licenses/MIT) |
| 10 | +[](https://packagist.org/packages/pulkitjalan/google-apiclient) |
| 11 | +[](https://packagist.org/packages/pulkitjalan/google-apiclient) |
| 12 | + |
| 13 | +## Requirements |
| 14 | + |
| 15 | +This package requires PHP >=5.4 |
| 16 | + |
| 17 | +## Installation |
| 18 | + |
| 19 | +Install via composer - edit your `composer.json` to require the package. |
| 20 | + |
| 21 | +```js |
| 22 | +"require": { |
| 23 | + "pulkitjalan/google-apiclient": "dev-master" |
| 24 | +} |
| 25 | +``` |
| 26 | + |
| 27 | +Then run `composer update` in your terminal to pull it in. |
| 28 | + |
| 29 | +## Laravel |
| 30 | + |
| 31 | +To use in laravel add the following to the `providers` array in your `config/app.php` |
| 32 | + |
| 33 | +```php |
| 34 | +'PulkitJalan\Google\GoogleServiceProvider' |
| 35 | +``` |
| 36 | + |
| 37 | +Next add the following to the `aliases` array in your `config/app.php` |
| 38 | + |
| 39 | +```php |
| 40 | +'Google' => 'PulkitJalan\Google\Facades\Google' |
| 41 | +``` |
| 42 | + |
| 43 | +Finally run `php artisan config:publish pulkitjalan/google-apiclient` to publish the config file. |
| 44 | + |
| 45 | +## Usage |
| 46 | + |
| 47 | +The `Client` class takes an array as the first parameter, see example of config file below: |
| 48 | + |
| 49 | +```php |
| 50 | +return [ |
| 51 | + /* |
| 52 | + |---------------------------------------------------------------------------- |
| 53 | + | Google application name |
| 54 | + |---------------------------------------------------------------------------- |
| 55 | + */ |
| 56 | + 'application_name' => '', |
| 57 | + |
| 58 | + /* |
| 59 | + |---------------------------------------------------------------------------- |
| 60 | + | Google OAuth 2.0 access |
| 61 | + |---------------------------------------------------------------------------- |
| 62 | + | |
| 63 | + | Keys for OAuth 2.0 access, see the API console at |
| 64 | + | https://developers.google.com/console |
| 65 | + | |
| 66 | + */ |
| 67 | + 'client_id' => '', |
| 68 | + 'client_secret' => '', |
| 69 | + 'redirect_uri' => '', |
| 70 | + 'scopes' => [], |
| 71 | + 'access_type' => 'online', |
| 72 | + 'approval_prompt' => 'auto', |
| 73 | + |
| 74 | + /* |
| 75 | + |---------------------------------------------------------------------------- |
| 76 | + | Google developer key |
| 77 | + |---------------------------------------------------------------------------- |
| 78 | + | |
| 79 | + | Simple API access key, also from the API console. Ensure you get |
| 80 | + | a Server key, and not a Browser key. |
| 81 | + | |
| 82 | + */ |
| 83 | + 'developer_key' => '', |
| 84 | + |
| 85 | + /* |
| 86 | + |---------------------------------------------------------------------------- |
| 87 | + | Google service account |
| 88 | + |---------------------------------------------------------------------------- |
| 89 | + | |
| 90 | + | Set the information below to use assert credentials |
| 91 | + | Leave blank to use app engine or compute engine. |
| 92 | + | |
| 93 | + */ |
| 94 | + 'service' => [ |
| 95 | + /* |
| 96 | + |
| 97 | + */ |
| 98 | + 'account' => '', |
| 99 | + |
| 100 | + /* |
| 101 | + | Example ['https://www.googleapis.com/auth/cloud-platform'] |
| 102 | + */ |
| 103 | + 'scopes' => [], |
| 104 | + |
| 105 | + /* |
| 106 | + | Path to key file |
| 107 | + | Example storage_path().'/key/google.p12' |
| 108 | + */ |
| 109 | + 'key' => '', |
| 110 | + ] |
| 111 | +]; |
| 112 | +``` |
| 113 | + |
| 114 | +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. |
| 115 | + |
| 116 | +`NOTE: service => ['account'] is the service Email Address and not the Client ID!` |
| 117 | + |
| 118 | +Get `Google_Client` |
| 119 | +```php |
| 120 | +$client = new PulkitJalan\Google\Client($config); |
| 121 | +$googleClient = $client->getClient(); |
| 122 | +``` |
| 123 | + |
| 124 | +Laravel Example: |
| 125 | +```php |
| 126 | +$googleClient = Google::getClient(); |
| 127 | +``` |
| 128 | + |
| 129 | +Get a service |
| 130 | +```php |
| 131 | +$client = new PulkitJalan\Google\Client($config); |
| 132 | + |
| 133 | +// returns instance of \Google_Service_Storage |
| 134 | +$storage = $client->make('storage'); |
| 135 | + |
| 136 | +// list buckets example |
| 137 | +$storage->buckets->listBuckets('project id'); |
| 138 | + |
| 139 | +// get object example |
| 140 | +$storage->objects->get('bucket', 'object'); |
| 141 | +``` |
0 commit comments