title: PHP Fatal error: Uncaught Error: Class 'Google\Auth\OAuth2' not found in .../Client.php:954
body: <p>The following threads do not solve it for me:-</p>
  
  <p><a href="https://stackoverflow.com/questions/34691895/fatal-error-class-google-auth-oauth2-not-found">Fatal error: Class &#39;Google\Auth\OAuth2&#39; not found</a></p>
  
  <p><a href="https://stackoverflow.com/questions/33717954/class-google-auth-oauth2-not-found?rq=1">Class &#39;Google\Auth\OAuth2&#39; not found</a></p>
  
  <p><a href="https://stackoverflow.com/questions/50095134/fatal-error-uncaught-error-class-google-client-not-found">Fatal error: Uncaught Error: Class &#39;Google_Client&#39; not found</a></p>
  
  <p>and even this one:-</p>
  
  <p><a href="https://stackoverflow.com/questions/28351680/implementing-oauth2-login-fatal-error-class-google-service-not-found">Implementing Oauth2 login, Fatal error: Class &#39;Google_Service&#39; not found</a></p>
  
  <p>Hi everyone,</p>
  
  <p>The exact logs from the error_log are below:-</p>
  
  <pre><code>PHP Fatal error:  Uncaught Error: Class 'Google\Auth\OAuth2' not found in /home/.../public_html/.../google/Client.php:954
  Stack trace:
  #0 /home/.../public_html/.../google/Client.php(943): Google_Client-&gt;createOAuth2Service()
  #1 /home/.../public_html/.../google/Client.php(338): Google_Client-&gt;getOAuth2Service()
  #2 /home/.../public_html/.../logintest.php(39): Google_Client-&gt;createAuthUrl()
  #3 {main}
    thrown in /home/.../public_html/.../google/Client.php on line 954
  </code></pre>
  
  <p>Below are a few lines from the Client.php</p>
  
  <pre><code>  public function getOAuth2Service()
    {
      if (!isset($this-&gt;auth)) {
        $this-&gt;auth = $this-&gt;createOAuth2Service();
      }
  
      return $this-&gt;auth;
    }
  
    /**
     * create a default google auth object
     */
    protected function createOAuth2Service()
    {
      $auth = new OAuth2(
          [
            'clientId'          =&gt; $this-&gt;getClientId(),
            'clientSecret'      =&gt; $this-&gt;getClientSecret(),
            'authorizationUri'   =&gt; self::OAUTH2_AUTH_URL,
            'tokenCredentialUri' =&gt; self::OAUTH2_TOKEN_URI,
            'redirectUri'       =&gt; $this-&gt;getRedirectUri(),
            'issuer'            =&gt; $this-&gt;config['client_id'],
            'signingKey'        =&gt; $this-&gt;config['signing_key'],
            'signingAlgorithm'  =&gt; $this-&gt;config['signing_algorithm'],
          ]
      );
  
      return $auth;
    }
  
  </code></pre>
  
  <p>Line #3 of the stack trace indicates (to me) that the inclusion of autoload.php and Client.php is done correctly</p>
  
  <p>I am on shared hosting which is why I could not install via Composer. I just download and copied the files (as per <a href="https://github.com/googleapis/google-api-php-client#installation" rel="nofollow noreferrer">https://github.com/googleapis/google-api-php-client#installation</a>).</p>
  
  <p>This is how I included the files</p>
  
  <pre><code>set_include_path(get_include_path() . PATH_SEPARATOR . '/../google/');
  include_once __DIR__ . '/../google/autoload.php';
  require_once 'google/Client.php';
  require_once 'google/Service.php';
  </code></pre>
  
  <p>The error trigger at the following line in the PHP code:-</p>
  
  <pre><code>$url = $client-&gt;createAuthUrl();
  </code></pre>
  
  <p>Please help!</p>