【发布时间】:2018-04-30 06:34:59
【问题描述】:
我试图从谷歌表格中获取数据。但我面临的问题是找不到 Google_client。 PHP 版本已更新,我的 apiclient/src/google 中有 client.php
致命错误:未捕获的错误:在 C:\xampp\htdocs\TestCalon\calonan.php:3 中找不到类 'Google_Client' 堆栈跟踪:#0 {main} 在 C:\xampp\htdocs\TestCalon\calonan 中抛出.php 在第 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();
【问题讨论】:
-
在调用
$client = new Google_Client;之前,您应该在代码中加载 Google 类(库)文件。 -
得到它。非常感谢。
-
酷。将其发布为答案。
-
@HimanshuUpadhyay 我如何加载 Google 类库。
标签: php