scottybo/google-apiclient

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

5.0.0 2020-09-14 14:00 UTC

README

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

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

要求

此包需要PHP >=7.2

安装

通过composer安装 - 编辑你的composer.json文件以要求此包。

"require": {
    "scottybo/google-apiclient": "4.*"
}

然后在你的终端中运行composer update以将其拉入。

或使用composer require scottybo/google-apiclient

Laravel

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

scottybo\Google\GoogleServiceProvider::class

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

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

最后,运行php artisan vendor:publish --provider="scottybo\Google\GoogleServiceProvider" --tag="config"以发布配置文件。

正在寻找Laravel 5兼容版本?

查看原始包

用法

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或Compute Engine,请留空。

来自Google的升级文档

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

获取Google_Client

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

Laravel示例

$googleClient = Google::getClient();

获取服务

$client = new scottybo\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服务的完整列表。