Oauth2 login injection, Fatal error: Class 'Google_Service' not found

I am updating my site login from LightOpenID to Google Oauth 2.0.

When I need Client.php and Service / Oauth2.php, I get an error

Fatal error: class "Google_Service" was not found in / home / myname / repos / website _current / lib / google-api-php-client / src / Google / Service / Oauth2.php on line 32

The code I'm using (from my login.php file) is as follows:

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

I added the include path in 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" 

So, it seems that my Oauth2.php file cannot see that any of the others includes the class "Google_Service", which is one folder in "Service.php".

My folder structure is as follows:

 lib/ ... autoload.php ... functions.php ... google-api-php-client/ ... src/ ... Google/ (etc etc) public_html/ ... login/ ...login.php 

I have no idea why this is happening. The include path should be seen and displayed as the included path using phpinfo (); Can someone please give me some idea?

+6
source share
8 answers

Make sure you add a line before any other google require_once lines.

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

I had this last, and I had to scratch my head for 10 minutes.

+18
source

In the github instruction:

require_once 'google-api-php-client/autoload.php'; // or wherever autoload.php is located

In your case, it seems that the above URL should work fine.

+2
source

A new way to do this (around the beginning of 2016) is

 require_once("Google/autoload.php"); 

(Assuming you already set your include path to / path / to / google-api-php-client / src)

+2
source

As of November 2016

 require_once ... 'vendor/autoload.php'; 
+2
source

Now it is deprecated and moved to the Google Sub directory. Below is the new default path: google-api-php-client-master\src\Google\autoload.php

0
source

After what Durandal published, I tried, but a new way for me:

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

As soon as I did this, it worked. Thanks for the help.

0
source

For this version, https://github.com/google/google-api-php-client is a possible solution

 set_include_path("google-api-php-client/src/" . PATH_SEPARATOR . get_include_path()); //..... require_once 'Google/Service.php'; //..... 
-1
source

When working with Google API Integration

Fatal error: class 'abc' not found

Error

occurs when there is a certain difference between the library available in composer.json above and the library that actually loads automatically.

had the same problem just changed in my composer.json

 {"require": {"google/apiclient": "1.0.*@beta"}} 

to

 {"require": {"google/apiclient": "2.0.*"}} 

and then do php composer.phar update (make sure you provide the correct path for the .phar file)

-1
source

Source: https://habr.com/ru/post/982065/


All Articles