实施Oauth2登录,出现致命错误:找不到类"Google_Service" [英] Implementing Oauth2 login, Fatal error: Class 'Google_Service' not found
问题描述
我正在将网站的登录系统从LightOpenID更新为Google的Oauth 2.0.
I am updating my website's login system from LightOpenID to Google's Oauth 2.0.
当我需要Client.php和Service/Oauth2.php时,我会收到错误消息
When I require the Client.php and the Service/Oauth2.php I get an error
致命错误:在第32行的/home/myname/repos/website_current/lib/google-api-php-client/src/Google/Service/Oauth2.php中找不到类"Google_Service"
Fatal error: Class 'Google_Service' not found in /home/myname/repos/website_current/lib/google-api-php-client/src/Google/Service/Oauth2.php on line 32
我正在使用的代码(来自我的login.php文件)看起来像这样
The code I am using (from my login.php file) looks like this
require_once(dirname($_SERVER['DOCUMENT_ROOT']).'/lib/autoload.php');
require('Google/Client.php');
require('Google/Service/Oauth2.php');
echo "exit";
exit();
我在PHP.ini中(在/etc/php5/apache2/php.ini中)将include路径添加为
I have added the include path in the PHP.ini (in /etc/php5/apache2/php.ini) as
include_path = ".:/usr/local/lib/php:/home/myname/repos/website_current/lib/google-api-php-client/src"
因此,我的Oauth2.php文件似乎看不到其他任何内容,包括类"Google_Service"(位于"Service.php"中的一个文件夹).
So its seems my Oauth2.php file can't see any of the other includes including the class 'Google_Service' which is one folder up in 'Service.php'.
我的文件夹结构如下:
lib/
... autoload.php
... functions.php
... google-api-php-client/
... src/
... Google/ (etc etc)
public_html/
... login/
...login.php
我不知道为什么会这样.应该可以看到include路径,并使用phpinfo()将其显示为包含路径.有人可以给我一些见识吗?
I have no idea why this is occuring. The include path should be seen, and shows up as an included path using phpinfo(); Can someone please give me some insight?
推荐答案
请确保您在之前行添加任何其他Google"require_once"行.
Make sure you add the line BEFORE any other Google "require_once" lines.
require_once 'google-api-php-client/autoload.php';
我忍受了一次,让我挠了整整十分钟.
I had it last and it had me scratching my head for a good 10 minutes.
这篇关于实施Oauth2登录,出现致命错误:找不到类"Google_Service"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!