34 lines
922 B
PHP
34 lines
922 B
PHP
<?php
|
|
require_once __DIR__ . '/vendor/autoload.php';
|
|
|
|
// Path to the service account JSON file
|
|
$credentialsPath = __DIR__ . '/google_credentials.json';
|
|
|
|
// Spreadsheet ID from the user
|
|
$spreadsheetId = '1SSmQuR9quxeQbMKNMDkRe8-n1gU7WuEfsFaJ3WKFO-c';
|
|
|
|
// Range to read (adjust if necessary)
|
|
$range = 'A1:Z10';
|
|
|
|
try {
|
|
$client = new Google\Client();
|
|
$client->setAuthConfig($credentialsPath);
|
|
$client->addScope(Google\Service\Sheets::SPREADSHEETS_READONLY);
|
|
|
|
$service = new Google\Service\Sheets($client);
|
|
$response = $service->spreadsheets_values->get($spreadsheetId, $range);
|
|
$values = $response->getValues();
|
|
|
|
if (empty($values)) {
|
|
echo "No data found.\n";
|
|
} else {
|
|
echo "Data found in Spreadsheet:\n";
|
|
foreach ($values as $row) {
|
|
echo implode(" | ", $row) . "\n";
|
|
}
|
|
}
|
|
} catch (Exception $e) {
|
|
echo 'Error: ' . $e->getMessage() . "\n";
|
|
}
|
|
|