ttskch / pheetsu

PHP 库,用于将 Google Spreadsheets(如 sheetsu.com)CRUD 化

dev-master / 1.0.x-dev 2018-11-16 00:47 UTC

This package is not auto-updated.

Last update: 2024-09-15 02:01:16 UTC


README

Latest Stable Version Total Downloads

PHP 库,用于将 Google Spreadsheets(如 sheetsu.com)CRUD 化。

需求

  • PHP 5.6+

安装

$ composer require ttskch/pheetsu:@dev

使用

如果您有一个像 这个 这样的 Google Spreadsheet,

image

您可以通过 pheetsu 非常容易地对电子表格进行 CRUD 操作,如下所示。

使用 OAuth2 初始化

$pheetsu = \Ttskch\Pheetsu\Factory\PheetsuFactory::createOAuth(
    'google_oauth2_client_id',
    'google_oauth2_client_secret',
    'google_oauth2_redirect_uri',
    'google_oauth2_javascript_origin',
    '1JQkfd3dlyxFRuxIwGPnBnrxS-l-bLVw_BbHskxT9Nj4', // spreadsheet id
    'demo' // sheet name
);

// authenticate and be authorized with Google OAuth2.
$pheetsu->authenticate();

使用服务账户初始化

$pheetsu = \Ttskch\Pheetsu\Factory\PheetsuFactory::createServiceAccount(
    '/path/to/your/service-account-credentials.json',
    '1JQkfd3dlyxFRuxIwGPnBnrxS-l-bLVw_BbHskxT9Nj4', // spreadsheet id
    'demo' // sheet name
);

使用

$rows = $pheetsu->read();
var_dump($rows);

// array (size=3)
//   0 => 
//     array (size=3)
//       'id' => string '1' (length=1)
//       'name' => string 'Alice' (length=5)
//       'age' => string '20' (length=2)
//   1 => 
//     array (size=3)
//       'id' => string '2' (length=1)
//       'name' => string 'Bob' (length=3)
//       'age' => string '25' (length=2)
//   2 => 
//     array (size=3)
//       'id' => string '3' (length=1)
//       'name' => string 'Charlie' (length=7)
//       'age' => string '18' (length=2)

另请参阅 演示