pmmotors / google-apiclient
支持云平台和Laravel 4 & 5的Google API PHP客户端包装器
3.1.6
2018-03-08 19:32 UTC
Requires
- php: >=5.4.0
- google/apiclient: ^2.0
- illuminate/support: ~5
Requires (Dev)
- mockery/mockery: 0.9.*
- phpunit/phpunit: 4.*
README
支持云平台和Laravel 4 & 5的Google API PHP客户端包装器
要求
此包需要PHP >=5.4
安装
通过composer安装 - 编辑你的composer.json以要求此包。
"require": { "pmmotors/google-apiclient": "3.*" }
然后在你的终端中运行composer update来拉取它。
或者使用composer require pmmotors/google-apiclient
Laravel
要在Laravel中使用,将以下内容添加到你的config/app.php中的providers数组
PmMotors\Google\GoogleServiceProvider::class
接下来,将以下内容添加到你的config/app.php中的aliases数组
'Google' => PmMotors\Google\Facades\Google::class
最后,运行php artisan vendor:publish --provider="PmMotors\Google\GoogleServiceProvider" --tag="config"以发布配置文件。
寻找Laravel 4兼容版本?
查看1.0分支
用法
Client类接受一个数组作为第一个参数,下面是配置文件的示例
<?php return [ /* |---------------------------------------------------------------------------- | Google application name |---------------------------------------------------------------------------- */ 'application_name' => env('GOOGLE_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' => env('GOOGLE_CLIENT_ID', ''), 'client_secret' => env('GOOGLE_CLIENT_SECRET', ''), 'redirect_uri' => env('GOOGLE_REDIRECT', ''), 'scopes' => array('https://www.googleapis.com/auth/analytics.readonly'), //[], 'access_type' => 'offline', //'online', 'approval_prompt' => 'auto', 'refresh_token' => env('GOOGLE_REFRESH_TOKEN', ''), /* |---------------------------------------------------------------------------- | 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' => env('GOOGLE_DEVELOPER_KEY', ''), /* |---------------------------------------------------------------------------- | Google service account |---------------------------------------------------------------------------- | | Set the credentials JSON's location to use assert credentials, otherwise | app engine or compute engine will be used. | */ 'service' => [ /* | Enable service account auth or not. */ 'enable' => env('GOOGLE_SERVICE_ENABLED', false), /* | Path to service account json file */ 'file' => env('GOOGLE_SERVICE_ACCOUNT_JSON_LOCATION', '') ], ];
要使用Google Cloud Platform服务,请输入服务账户JSON文件的路径(不是JSON字符串本身)。要使用App Engine或Compute Engine,请留空。
注意:P12已弃用,现在推荐使用服务账户JSON,这可以在Google开发者控制台的“凭证”部分生成。
获取Google_Client
$client = new PmMotors\Google\Client($config); $googleClient = $client->getClient();
Laravel示例
$googleClient = Google::getClient();
获取服务
$client = new PmMotors\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');
Laravel示例
// returns instance of \Google_Service_Storage $storage = Google::make('storage'); // list buckets example $storage->buckets->listBuckets('project id'); // get object example $storage->objects->get('bucket', 'object');
查看google/google-api-php-client-services以获取支持的Google服务的完整列表。