【发布时间】:2015-04-01 00:43:09
【问题描述】:
用于设置 Google Drive API 以使用 PHP 的 Google 文档示例具有这样的要求语句:
<?php
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_DriveService.php';
other code
?>
我从 GitHub 下载了一个 .zip 文件,并将其解压缩。在提取的文件夹和文件中,来自 GitHub 的 google-api-php-client 文件不包含名为 Google_Client.php 的文件。在 src/Google/ 目录中有一个名为 Client.php 的文件。
而且也没有 contrib 文件夹。
AND,GitHub google-api的下载中没有名为DriveService.php的文件-php-client 文件。
所以,我假设对文件和文件夹的引用应该如下所示:
<?php
require_once 'google-api-php-client/src/Google/Client.php';
require_once 'google-api-php-client/src/Google/Drive.php';
other code
?>
Client.php 文件包含 require_once 语句,用于 autoload.php 文件:
if (!class_exists('Google_Client')) {
require_once dirname(__FILE__) . '/../autoload.php';
}
引用/../ 中的双点表示当正在搜索文件autoload.php 以便包含时,转到父文件夹,并在那里搜索。
所以文件夹结构应该是:
src - Folder
autoload.php
Google - Folder
Client.php
DriveService.php
autoload.php文件代码为:
<?php
function google_api_php_client_autoload($className)
{
$classPath = explode('_', $className);
if ($classPath[0] != 'Google') {
return;
}
// Drop 'Google', and maximum class file path depth in this project is 3.
$classPath = array_slice($classPath, 1, 2);
$filePath = dirname(__FILE__) . '/' . implode('/', $classPath) . '.php';
if (file_exists($filePath)) {
require_once($filePath);
}
}
spl_autoload_register('google_api_php_client_autoload');
Drive.php 文件中没有 require 或 include 语句。
下载的文件中还有一个Service文件夹,Google文件夹中有一个Service.php文件。 p>
文档是否错误,我的建议是否正确? PHP 中 Drive API 的正确设置是什么?
【问题讨论】:
标签: php google-app-engine google-drive-api require