Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am updating my website's login system from LightOpenID to Google's Oauth 2.0.

When I require the Client.php and the Service/Oauth2.php I get an error

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

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();

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"

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'.

My folder structure looks like this:

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 occuring. The include path should be seen, and shows up as an included path using phpinfo(); Can someone please give me some insight?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
603 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...