Implementing Oauth2 login, Fatal error: Class 'Google_Service' not found
Implementing Oauth2 login, Fatal error: Class 'Google_Service' not found
我正在将我网站的登录系统从 LightOpenID 更新到 Google 的 Oauth 2.0。
当我需要 Client.php 和 Service/Oauth2.php 时,出现错误
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 文件)如下所示
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_path = ".:/usr/local/lib/php:/home/myname/repos/website_current/lib/google-api-php-client/src"
所以我的 Oauth2.php 文件似乎看不到任何其他内容,包括 class 'Google_Service',它是 'Service.php' 中的一个文件夹。
我的文件夹结构如下所示:
lib/
... autoload.php
... functions.php
... google-api-php-client/
... src/
... Google/ (etc etc)
public_html/
... login/
...login.php
我不知道为什么会这样。应该可以看到包含路径,并使用 phpinfo(); 显示为包含路径;有人可以给我一些见解吗?
根据 github 上的说明:
require_once 'google-api-php-client/autoload.php'; // or wherever autoload.php is located
在你的情况下,上面的 include url 应该可以正常工作。
确保在 之前添加 任何其他 Google "require_once" 行。
require_once 'google-api-php-client/autoload.php';
我坚持到最后,它让我挠头足足有 10 分钟。
现已弃用并移至子 Google 目录。以下是新的默认路径:
google-api-php-client-master\src\Google\autoload.php
按照 Durandal 发布的内容进行了尝试,但对我来说新的路径是:
require_once 'google-api-php-client/src/Google/autoload.php';
一旦我做了这个改变,它就起作用了。感谢您的帮助。
执行此操作的新方法(大约 2016 年初)是
require_once("Google/autoload.php");
(假设您已经将包含路径设置为 /path/to/google-api-php-client/src)
对于这个版本https://github.com/google/google-api-php-client这是一个可能的解决方案
set_include_path("google-api-php-client/src/" . PATH_SEPARATOR . get_include_path());
//.....
require_once 'Google/Service.php';
//.....
在使用 Google API 集成时
Fatal error: Class 'abc' not found
当上面 composer.json
中的库与实际自动加载的库之间肯定存在差异时,就会出现错误。
我的 composer.json
遇到了同样的问题
{"require": {"google/apiclient": "1.0.*@beta"}}
至
{"require": {"google/apiclient": "2.0.*"}}
然后执行php composer.phar update
(确保为.phar
文件提供正确的路径)
截至 2016 年 11 月
require_once ... 'vendor/autoload.php';
我正在将我网站的登录系统从 LightOpenID 更新到 Google 的 Oauth 2.0。
当我需要 Client.php 和 Service/Oauth2.php 时,出现错误
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 文件)如下所示
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_path = ".:/usr/local/lib/php:/home/myname/repos/website_current/lib/google-api-php-client/src"
所以我的 Oauth2.php 文件似乎看不到任何其他内容,包括 class 'Google_Service',它是 'Service.php' 中的一个文件夹。
我的文件夹结构如下所示:
lib/
... autoload.php
... functions.php
... google-api-php-client/
... src/
... Google/ (etc etc)
public_html/
... login/
...login.php
我不知道为什么会这样。应该可以看到包含路径,并使用 phpinfo(); 显示为包含路径;有人可以给我一些见解吗?
根据 github 上的说明:
require_once 'google-api-php-client/autoload.php'; // or wherever autoload.php is located
在你的情况下,上面的 include url 应该可以正常工作。
确保在 之前添加 任何其他 Google "require_once" 行。
require_once 'google-api-php-client/autoload.php';
我坚持到最后,它让我挠头足足有 10 分钟。
现已弃用并移至子 Google 目录。以下是新的默认路径:
google-api-php-client-master\src\Google\autoload.php
按照 Durandal 发布的内容进行了尝试,但对我来说新的路径是:
require_once 'google-api-php-client/src/Google/autoload.php';
一旦我做了这个改变,它就起作用了。感谢您的帮助。
执行此操作的新方法(大约 2016 年初)是
require_once("Google/autoload.php");
(假设您已经将包含路径设置为 /path/to/google-api-php-client/src)
对于这个版本https://github.com/google/google-api-php-client这是一个可能的解决方案
set_include_path("google-api-php-client/src/" . PATH_SEPARATOR . get_include_path());
//.....
require_once 'Google/Service.php';
//.....
在使用 Google API 集成时
Fatal error: Class 'abc' not found
当上面 composer.json
中的库与实际自动加载的库之间肯定存在差异时,就会出现错误。
我的 composer.json
{"require": {"google/apiclient": "1.0.*@beta"}}
至
{"require": {"google/apiclient": "2.0.*"}}
然后执行php composer.phar update
(确保为.phar
文件提供正确的路径)
截至 2016 年 11 月
require_once ... 'vendor/autoload.php';