致命错误:未捕获错误:类' Google_Client'未找到

时间:2018-04-30 06:34:59

标签: php

我试图从谷歌表中获取数据。但我遇到的问题是找不到Google_client。 Php版本已更新,我的apiclient / src / google

中有client.php

致命错误:未捕获错误:类' Google_Client'在C:\ xampp \ htdocs \ TestCalon \ calonan.php中找不到:3堆栈跟踪:在第3行的C:\ xampp \ htdocs \ TestCalon \ calonan.php中抛出#0 {main}

<?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();

1 个答案:

答案 0 :(得分:0)

在致电$ client = new Google_Client之前;您应该在代码中加载Google类(库)文件。

缺少这种情况,导致错误。

相关问题