jaeger/pulkitjalan-google-apiclient

支持云平台和Laravel 4 & 5的Google API PHP客户端包装器

3.0.1 2016-09-04 16:00 UTC

This package is auto-updated.

Last update: 2024-09-09 16:12:03 UTC


README

支持云平台和Laravel 4 & 5的Google API PHP客户端包装器

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

要求

此包需要PHP >=5.4

安装

通过composer安装 - 编辑你的 composer.json 以包含此包。

"require": {
    "pulkitjalan/google-apiclient": "3.*"
}

然后在你的终端中运行 composer update 以拉取它。

或者使用 composer require pulkitjalan/google-apiclient

Laravel

要在Laravel中使用,请将以下内容添加到你的 config/app.php 中的 providers 数组

PulkitJalan\Google\GoogleServiceProvider::class

接下来,将以下内容添加到你的 config/app.php 中的 aliases 数组

'Google' => PulkitJalan\Google\Facades\Google::class

最后,运行 php artisan vendor:publish --provider="PulkitJalan\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 credentials JSON's location to use assert credentials, otherwise
    | app engine or compute engine will be used.
    |
    */
    'service' =>  [
        /*
        | Enable service account auth or not.
        */
        'enabled' => false,

        /*
        | Path to service account json file
        */
        'file' => '',
    ],
];

要使用Google云平台服务,输入服务帐户JSON文件的位置(不是JSON字符串本身)。要使用App Engine或Compute Engine,请留空。

Google的升级文档

注意:P12s已被服务帐户JSON取代,这可以在Google开发者控制台中的凭据部分生成。

获取 Google_Client

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

Laravel 示例

$googleClient = Google::getClient();

获取服务

$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');