谷歌API autoload.php丢失

时间:2014-11-17 23:25:44

标签: php google-api-php-client

之前我从未使用过Goodle API,现在我尝试通过API访问Google日历。

我下载了google-api-php-client-master.zip,提取了... / src / Google目录并将其复制到我的网络服务器(由第三方托管,这意味着我无法安装任何东西) 。根据示例,我的代码需要以

开头
<?php
require_once "Google/Client.php";
require_once "Google/Service/Calendar.php";
....

但是Client.php会抛出错误:

致命错误:require_once():在/ homepages / 39 / d396519017 / htdocs / VC2 / Google / Client中未能打开所需的''(include_path ='。:/ usr / lib / php5.4')。第18行的php

Client.php-Line 18就是这一行require_once realpath(dirname(__FILE__) . '/../../autoload.php');

但我无法在任何地方找到autoload.php。我错过了什么?

谢谢!

1 个答案:

答案 0 :(得分:7)

This is the autoload.php file that you're looking for

更好(并且更容易)不用担心单独加载每个类文件,并将这个autoload.php文件包含在您将要开始使用的示例的顶部!确保将文件放在包含src目录的文件夹中。

您还可以follow the installation documentation并使用以下内容在包含路径中设置src文件夹:

set_include_path(get_include_path() . PATH_SEPARATOR . '/path/to/google-api-php-client/src');

在执行上述任一操作时,您必须使用use语句来包含所需的类。

更新:谷歌已经转向纯粹使用Composer的最新版本as per this issue。您应该安装Composer并运行composer require "google/apiclient:~2.0@dev"以获取所需的autoload.php文件,或者在repo中使用v1.x.x标记。我已将autoload.php链接更新为最新的v1标记。