实施Oauth2登录,致命错误:找不到类'Google_Service'

Gam*_*les 7 php oauth-2.0 google-oauth google-api-php-client

我正在将我的网站登录系统从LightOpenID更新为Google的Oauth 2.0.

当我需要Client.php和Service/Oauth2.php时,我收到错误

致命错误:第32行/home/myname/repos/website_current/lib/google-api-php-client/src/Google/Service/Oauth2.php中未找到"Google_Service"类

我正在使用的代码(来自我的login.php文件)看起来像这样

require_once(dirname($_SERVER['DOCUMENT_ROOT']).'/lib/autoload.php');
require('Google/Client.php');
require('Google/Service/Oauth2.php');
echo "exit";
exit();
Run Code Online (Sandbox Code Playgroud)

我在PHP.ini中添加了include路径(在/etc/php5/apache2/php.ini中)

include_path = ".:/usr/local/lib/php:/home/myname/repos/website_current/lib/google-api-php-client/src"
Run Code Online (Sandbox Code Playgroud)

所以它似乎我的Oauth2.php文件看不到任何其他包括类'Google_Service',这是'Service.php'中的一个文件夹.

我的文件夹结构如下所示:

lib/
... autoload.php
... functions.php
... google-api-php-client/
    ... src/
        ... Google/ (etc etc)
public_html/
... login/
    ...login.php
Run Code Online (Sandbox Code Playgroud)

我不知道为什么会这样.应该看到包含路径,并使用phpinfo()显示为包含的路径; 有人可以给我一些见解吗?

小智 18

确保任何其他Google"require_once" 行之前添加该行.

require_once 'google-api-php-client/autoload.php';
Run Code Online (Sandbox Code Playgroud)

我把它弄到最后,它让我挠了头10分钟.

  • autoload.php已被移动 - 现在使用:require_once'Google/autoload.php'; (6认同)