irisdande / lara5-googleclient-api
支持云平台和Laravel 4 & 5的Google api PHP客户端包装器
dev-master / 2.0.x-dev
2016-07-19 07:55 UTC
Requires
- php: >=5.4.0
- google/apiclient: 1.*
- illuminate/support: ~5
Requires (Dev)
- mockery/mockery: 0.9.*
- phpunit/phpunit: 4.*
This package is not auto-updated.
Last update: 2024-09-23 06:30:30 UTC
README
支持云平台和Laravel 4 & 5的Google api PHP客户端包装器
要求
此包需要PHP >=5.4
安装
通过composer安装 - 编辑你的 composer.json
文件以添加包依赖。
"require": { "irisdande/lara5-googleclient-api": "2.*" }
然后在你的终端中运行 composer update
来拉取它。
或者使用 composer require irisdande/lara5-googleclient-api
Laravel
要在Laravel中使用,请将以下内容添加到你的 config/app.php
文件中的 providers
数组
IrisDande\Google\GoogleServiceProvider::class
然后添加以下内容到你的 config/app.php
文件中的 aliases
数组
'Google' => IrisDande\Google\Facades\Google::class
最后运行 php artisan vendor:publish --provider="IrisDande\Google\GoogleServiceProvider" --tag="config"
来发布配置文件。
在寻找Laravel 4兼容版本?
查看 1.0分支
用法
Client
类接受一个数组作为第一个参数,下面是配置文件的示例
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' => '', ] ];
要使用Google云平台服务,你可以在配置文件中的 service
下设置信息,或者如果在计算引擎(或应用引擎)下运行,则将其留空。
注意:service => ['account'] 是服务电子邮件地址,而不是客户端ID!
获取 Google_Client
$client = new IrisDande\Google\Client($config); $googleClient = $client->getClient();
Laravel 示例
$googleClient = Google::getClient();
获取服务
$client = new IrisDande\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');