Class “Google_Config” not found

前端 未结 6 573
太阳男子
太阳男子 2021-01-18 02:48

I\'m trying to implement Google\'s login API via the instructions here, but for some reason, when I try to run it, I always get:

Fatal error: Class \'

相关标签:
6条回答
  • 2021-01-18 03:03

    google's autoloader doesn't work for me, it's either because of an old version of PHP or a conflict with a competing autoloader, I don't know.

    I have even tried manually including googles auto loader (which should be redundant as src/Google/Client.php already require_once's the autoload.php:

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

    Google_Config is never found...

    ultimatly the only solution is the solution as described in https://stackoverflow.com/a/26985116/3338098 i.e.

    set_include_path(get_include_path() . PATH_SEPARATOR . '/path/to/google-api-php-client/src');
    require_once 'Google/Client.php'
    
    0 讨论(0)
  • 2021-01-18 03:04

    Are you sure you downloaded whole release not only master branch from github? You should have /vendors and /src directories - then require /src/autoload.php

    0 讨论(0)
  • 2021-01-18 03:05

    This error means that you didn't use Composer, to install the client. Without Composer, in your script you should

    set_include_path(get_include_path() . PATH_SEPARATOR . dirname($_SERVER['SCRIPT_FILENAME']) . 'vendor/google-api-php-client/src');  
    require_once '/path/to/autoload.php';  
    require_once '/path/to/Client.php';
    

    Without the autoload.php, no class will be found. In Client.php the code before the Class definition tries to load autoload.php. But you have already found the Client.php, by giving the full path to it. So no loading of autoload.php happens there.

    As you say, your problem solved when you reinstalled the API. I suppose you used Composer the second time.

    Clarification: The above note does NOT mean to skip proper client installation, according to google documentation. Applies for "google/apiclient": "1.0.*@beta"

    0 讨论(0)
  • 2021-01-18 03:22

    I fought with this for a while. The reason was actually quite simple:

    I had ignored in git "config.php" which ignored this file and that's why it was not in my production environment.

    0 讨论(0)
  • 2021-01-18 03:24

    I could solve the problem by following steps

    > cd "youfolder"
    > composer install
    
    0 讨论(0)
  • 2021-01-18 03:24

    Instead of keeping vendor folder in root folder, keep it in google-api-php-client-master folder and use the following line to include it in your project

    require_once DIR.'/google-api-php-client-master/vendor/autoload.php';

    0 讨论(0)
提交回复
热议问题