Google Spreadsheet Client for PHP. This requires "google/apiclient" package.
- Log in Google Developper Console
- Create new project
- Create Service Account credentials in the project
- Download key file as JSON
- Create a new spreadsheet in Google Drive
- Authorize the email address, which is found as "client_email" in key file, to read and edit.
- Save the file ID from address bar.
$client = Google_Spreadsheet::getClient("the/path/to/credential.json");
// Get the file by file ID
$file = $client->file("XXXxxxXXXXxxxXXXX");
// Get the sheet by title
$sheet = $file->sheet("Sheet1");
// Flush all rows in the sheet
var_dump($sheet->items);
// Array
$items = $sheet->select(array("id" => "1"));
// Closure
$items = $sheet->select(function($row){
return (int) $row["age"] < 30;
});
$sheet->insert(array(
"name" => "John",
"age" => 23,
"email" => "[email protected]"
));
$sheet->update(
8, // row number
"name", // field's name (or column number as Integer)
"Tom"
);
$items = $sheet->fetch(true)->items;
$client->config(array(
"cache" => true,
"cache_dir" => "cache",
"cache_expires" => 3600
));
- google/apiclient (Apache License v2.0)