【发布时间】:2015-03-26 02:02:45
【问题描述】:
这是我的 composer.json:
{
"require": {
"google/apiclient": "1.0.*@beta"
}
}
这是我的代码:
<?
$path = get_include_path() . PATH_SEPARATOR . 'C:\wamp\www\gCalendar\vendor\google\apiclient\src';
set_include_path($path);
define("APIKEY","AIxxxxxxxWA");
define("CLIENTID","xxxkqt.apps.googleusercontent.com");
define("CLIENTSECRET","xxxx");
define("DEVELOPERKEY","xxx.apps.googleusercontent.com");
require_once("config.php");
require_once("vendor/autoload.php");
session_start();
$scriptUri = "http://".$_SERVER["HTTP_HOST"].$_SERVER['PHP_SELF'];
$client = new Google_Client();
$client->setAccessType('online'); // default: offline
$client->setApplicationName('CalendarTest');
$client->setClientId(CLIENTID);
$client->setClientSecret(CLIENTSECRET);
$client->setRedirectUri($scriptUri);
$client->setDeveloperKey(APIKEY); // API key
// $service implements the client interface, has to be set before auth call
$service = new Google_AnalyticsService($client);
if (isset($_GET['logout'])) { // logout: destroy token
unset($_SESSION['token']);
die('Logged out.');
}
if (isset($_GET['code'])) { // we received the positive auth callback, get the token and store it in session
$client->authenticate();
$_SESSION['token'] = $client->getAccessToken();
}
if (isset($_SESSION['token'])) { // extract token from session and configure client
$token = $_SESSION['token'];
$client->setAccessToken($token);
}
if (!$client->getAccessToken()) { // auth call to google
$authUrl = $client->createAuthUrl();
header("Location: ".$authUrl);
die;
}
echo 'Hello, world.';
?>
我已返回此错误:
( ! ) Fatal error: Class 'Google_AnalyticsService' not found in C:\wamp\www\gCalendar\index.php on line 21
我做错了什么,包括带有 Composer 的库?
非常感谢
【问题讨论】:
标签: composer-php google-api-php-client google-api-client