PHP使用关键字命名空间不查找类

时间:2015-04-29 03:41:08

标签: php class google-api

怪诞。任何想法为什么找不到这个班级?

目录树:

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 /添加到使用路径时,没有工作,我尝试一起删除路径,都没有做任何事。

错误:致命错误:第15行的test2.php中找不到类'src \ Google \ Spreadsheet \ Google_Client'

0 个答案:

没有答案