实现 Oauth2 登录,致命错误:找不到“Google_Service"类

2023-05-31php开发问题
11

本文介绍了实现 Oauth2 登录,致命错误:找不到“Google_Service"类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在将我网站的登录系统从 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 中)添加了包含路径

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

我不知道为什么会发生这种情况.应该可以看到包含路径,并使用 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?

推荐答案

确保您在任何其他 Googlerequire_once"行BEFORE之前添加该行.

Make sure you add the line BEFORE any other Google "require_once" lines.

require_once 'google-api-php-client/autoload.php';

我最后吃了它,它让我挠了 10 分钟.

I had it last and it had me scratching my head for a good 10 minutes.

这篇关于实现 Oauth2 登录,致命错误:找不到“Google_Service"类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17