adexaja/laravel-autodrive

支持 Google Cloud Platform 和 Laravel 4 & 5 的 PHP 客户端包装器

3.0.0 2016-07-20 07:11 UTC

This package is not auto-updated.

Last update: 2024-09-23 13:52:31 UTC


README

支持 Google Cloud Platform 和 Laravel 4 & 5 的 PHP 客户端包装器

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

要求

此包需要 PHP >=5.4

安装

使用 composer 安装 - 编辑您的 composer.json 以要求此包。

"require": {
    "adexaja/laravel-autodrive": "3.*"
}

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

或使用 composer require adexaja/laravel-autodrive

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 Cloud Platform 服务,输入服务帐户 JSON 文件的路径 (不是 JSON 字符串本身)。要使用 App Engine 或 Computer 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');

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 服务的完整列表。