怪异。你知道为什么它找不到这个类吗?
目录树:
test2.php
- src
- Google
- Spreadsheet
DefaultServiceRequest.php
ServiceRequestInterface.php
Google_Client.php
...
test2.php:
namespace src\Google\Spreadsheet;
require_once 'src/Google/Spreadsheet/ServiceRequestInterface.php';
require_once 'src/Google/Spreadsheet/DefaultServiceRequest.php';
require_once 'src/Google/Spreadsheet/Google_Client.php';
use Google\Spreadsheet\ServiceRequestInterface;
use Google\Spreadsheet\DefaultServiceRequest;
use Google\Spreadsheet\ServiceRequestFactory;
function getGoogleTokenFromKeyFile($clientId, $clientEmail, $pathToP12File) {
require 'src/Google/Spreadsheet/Google_Client.php';
$client = new Google_Client();
$client->setClientId($clientId);
$cred = new Google_Auth_AssertionCredentials(
$clientEmail,
array('https://spreadsheets.google.com/feeds'),
file_get_contents($pathToP12File)
);
$client->setAssertionCredentials($cred);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
$service_token = json_decode($client->getAccessToken());
return $service_token->access_token;
}
$serviceRequest = new DefaultServiceRequest(getGoogleTokenFromKeyFile(..., ..., ...));
ServiceRequestFactory::setInstance($serviceRequest);
不确定这是否与Google API相关或什么。奇怪的是,ServiceRequest类只有在我需要它们时才能工作。当我找不到的时候,它说找不到它...当我尝试将src/添加到use path中时,不起作用,并且我尝试一起删除该路径,所有操作都没有执行任何操作。
错误:致命错误:在第15行的test2.php中找不到类'src\Google\Spreadsheet\Google_Client‘
发布于 2015-04-29 23:15:17
看起来您正在使用this库
如果使用composer安装库,则需要在代码中包含vendor/autoload.php
文件
require 'vendor/autoload.php';
建议您使用composer安装此库,但如果您不想使用composer,则需要创建自动加载器并在代码中require
它
https://stackoverflow.com/questions/29933922
复制相似问题