ttskch / google-sheets-api-php-client
Google Sheets API 的 PHP 客户端库。
dev-master / 1.0.x-dev
2018-11-09 08:14 UTC
Requires
- php: >=5.6.0
- google/apiclient: ^2.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.3
- phpmd/phpmd: ^2.6
- phpunit/phpunit: ^5.7 || ^6.0
- squizlabs/php_codesniffer: ^2.8
This package is not auto-updated.
Last update: 2024-09-20 06:51:14 UTC
README
Google Sheets API 的 PHP 客户端库。
要求
- PHP 5.6+
安装
$ composer require ttskch/google-sheets-api-php-client:@dev
用法
初始化 API 客户端
使用 OAuth2
// create \Google_Client instance with your OAuth2 client ID. $googleClient = \Ttskch\GoogleSheetsApi\Factory\GoogleClientFactory::createOAuthClient( 'client_id', 'client_secret', 'redirect_uri', 'javascript_origin' ); // authenticate and be athorized. $authenticator = new \Ttskch\GoogleSheetsApi\Authenticator($googleClient); if (isset($_GET['code'])) { $authenticator->authenticate($_GET['code']); } else { $authenticator->authorize(); }
使用服务帐户
// create \Google_Client instance with your Service Account credentials json file. $googleClient = \Ttskch\GoogleSheetsApi\Factory\GoogleClientFactory::createServiceAccountClient('/path/to/service-account-credentials.json');
使用 API
// create API client with authorized \Google_Client. $api = \Ttskch\GoogleSheetsApi\Factory\ApiClientFactory::create($googleClient); $service = $api->getGoogleService(); // now you can call all apis via $service. // see \Google_Service_Sheets class to learn more about details. $service->spreadsheets->...; $service->spreadsheets_sheets->...; $service->spreadsheets_values->...;
另请参阅 示例。