0

I trying to get data from google sheets. but what problem i face is Google_client not found. Php version is updated and i do have client.php in my apiclient/src/google

Fatal error: Uncaught Error: Class 'Google_Client' not found in C:\xampp\htdocs\TestCalon\calonan.php:3 Stack trace: #0 {main} thrown in C:\xampp\htdocs\TestCalon\calonan.php on line 3

<?php
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . __DIR__ . '/client_secret.json');
$client = new Google_Client;
$client->useApplicationDefaultCredentials();

$client->setApplicationName("Something to do with my representatives");
$client->setScopes(['https://www.googleapis.com/auth/drive','https://spreadsheets.google.com/feeds']);

if ($client->isAccessTokenExpired()) {
    $client->refreshTokenWithAssertion();
}

$accessToken = $client->fetchAccessTokenWithAssertion()["access_token"];
ServiceRequestFactory::setInstance(
    new DefaultServiceRequest($accessToken)
);

$spreadsheet = (new Google\Spreadsheet\SpreadsheetService)
   ->getSpreadsheetFeed()
   ->getByTitle('Copy of PRU14 Calon');

// Get the first worksheet (tab)
$worksheets = $spreadsheet->getWorksheetFeed()->getEntries();
$worksheet = $worksheets[0];

$listFeed = $worksheet->getListFeed();

/** @var ListEntry */
foreach ($listFeed->getEntries() as $entry) {
   $representative = $entry->getValues();
}

$cellFeed = $worksheet->getCellFeed();

$rows = $cellFeed->toArray();

return $worksheet->getCsv();
joey
  • 73
  • 2
  • 13

1 Answers1

0

Before you call $client = new Google_Client; you should load the Google class (library) file in you code.

That is missing and so resulting as an error.

Himanshu Upadhyay
  • 6,438
  • 1
  • 16
  • 32
  • How could I load the file? By means of Google/src/Client.php loading and functions like require/require_once I cannot fix anything. – anrequete Oct 01 '18 at 14:44