缺少Google API autoload.php
我以前从未使用过Goodle API,现在尝试通过该API访问Google日历.
I never used the Goodle API before, and now I try to get my feet wet accessing Google calendar via the API.
我下载了google-api-php-client-master.zip,解压缩了.../src/Google目录,并将其复制到了我的网络服务器(由第三方托管,这意味着我无法安装任何东西) .根据示例,我的代码需要以
I downloaded the google-api-php-client-master.zip, extracted the .../src/Google directory and copied it to my webserver (hosted by a 3rd party, which means I can't install anything). According to the samples my code needs to start with
<?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第18行是此行require_once realpath(dirname(__FILE__) . '/../../autoload.php');
Client.php-Line 18 is this line require_once realpath(dirname(__FILE__) . '/../../autoload.php');
但是我无法在任何地方查找autoload.php.我想念什么?
But I can't fint autoload.php anywhere. What am I missing?
谢谢!
最好不要担心单独加载每个类文件,而要在要开始使用的示例顶部包括此autoload.php
文件!确保将文件放置在保存src
目录的文件夹中.
It is much better (and easier) to not worry about loading each class file individually and including this autoload.php
file at the top of the examples that you're going to start working with! Make sure you place the file at the folder that holds the src
directory.
您还可以遵循安装文档并设置src
包含路径中的src
文件夹,使用:
You could also follow the installation documentation and set the src
folder in your include path using:
set_include_path(get_include_path() . PATH_SEPARATOR . '/path/to/google-api-php-client/src');
执行上述任一操作时,必须改为使用use
语句来包含所需的类.
When doing either of these things, you must instead utilize use
statements to include the classes that you need.
更新:Google已移至纯粹使用Composer的最新版本按照这个问题.您应该安装Composer并运行composer require "google/apiclient:~2.0@dev"
以获取所需的autoload.php文件,或者在存储库中使用v1.x.x
标记.我已经将autoload.php链接更新为最新的v1标签.
UPDATE: Google has moved to purely using Composer in its bleeding edge versions as per this issue. You should install Composer and run composer require "google/apiclient:~2.0@dev"
to get the autoload.php file you need, or use a v1.x.x
tag in the repo. I've updated the autoload.php link to the latest v1 tag.