PHP code example of ceytek-labs / google-services-lite
1. Go to this page and download the library: Download ceytek-labs/google-services-lite library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ceytek-labs / google-services-lite example snippets
use CeytekLabs\GoogleServicesLite\GoogleSheets;
$result = GoogleSheets::make('SPREADSHEET_ID') // Set the ID of the Google Sheets document
->setCredentials(__DIR__.'/credentials.json') // Set the authentication file
->update('Sheet1', [ // Set the name of the tab where data will be updated
["Data 1", "Data 2", "Data 3"], // Add the data to be updated
["Data 4", "Data 5", "Data 6"],
["Data 7", "Data 8", "Data 9"],
]);
echo 'Number of updated cells: ' . $result['updated_cells_count'];
use CeytekLabs\GoogleServicesLite\GoogleSheets;
$result = GoogleSheets::make('SPREADSHEET_ID') // Set the ID of the Google Sheets document
->setCredentials(__DIR__.'/credentials.json') // Set the authentication file
->updateInChunks('Sheet1', [ // Update data in smaller chunks
["Data 1", "Data 2", "Data 3"], // Add the data to be updated
["Data 4", "Data 5", "Data 6"],
["Data 7", "Data 8", "Data 9"], // For large datasets, the data will be split into chunks
], 50); // Define the chunk size (e.g., 50 rows)
echo 'Number of updated cells: ' . $result['updated_cells_count'];
use CeytekLabs\GoogleServicesLite\GoogleSheets;
$result = GoogleSheets::make('SPREADSHEET_ID') // Set the ID of the Google Sheets document
->setCredentials(__DIR__.'/credentials.json') // Set the authentication file
->batchUpdate('Sheet1', [ // Set the name of the tab where data will be updated
["Data 1", "Data 2", "Data 3"], // Add the data to be updated
["Data 4", "Data 5", "Data 6"],
["Data 7", "Data 8", "Data 9"],
]);
echo 'Batch update status: ' . ($result['status'] ? 'Success' : 'Failed');
use CeytekLabs\GoogleServicesLite\GoogleSheets;
$result = GoogleSheets::make('SPREADSHEET_ID') // Set the ID of the Google Sheets document
->setCredentials(__DIR__.'/credentials.json') // Set the authentication file
->batchUpdateInChunks('Sheet1', [ // Update data in smaller chunks
["Data 1", "Data 2", "Data 3"], // Add the data to be updated
["Data 4", "Data 5", "Data 6"],
["Data 7", "Data 8", "Data 9"], // For large datasets, the data will be split into chunks
], 750); // Define the chunk size (e.g., 750 rows)
echo 'Number of updated cells: ' . $result['updated_cells_count'];
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.