You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用Google Sheets数据时Google_Client类未找到错误求助

Fixing "Google_Client Class Not Found" Error in PHP for Google Sheets

Hey Joey, let’s work through this frustrating error you’re facing. I’ve dealt with this exact issue when integrating Google APIs, so here are the step-by-step fixes to get your Google Sheets data pull working again:

First, let’s recap your setup to make sure we’re on the same page

Your error message:

Fatal error: Uncaught Error: Class 'Google_Client' not found in C:\xampp\htdocs\TestCalon\calonan.php:3 Stack trace: #0 {main} thrown in C:\xampp\htdocs\TestCalon\calonan.php on line 3

Your code snippet:

<?php 
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . __DIR__ . '/client_secret.json'); 
$client = new Google_Client; 
$client->useApplicationDefault...

You mentioned your PHP version is updated, and client.php exists in apiclient/src/google/—great, so we can rule out missing core files. Now let’s tackle the common causes:


1. Fix Autoloader Setup (Most Likely Issue)

The Google API Client relies on an autoloader to load all its classes, not just client.php alone. If you’re not using Composer (the recommended way), you need to include Google’s built-in autoloader. Add this line at the very top of your calonan.php file:

require_once __DIR__ . '/apiclient/src/Google/autoload.php';

Make sure the path matches where your autoload.php is located relative to your script. If you are using Composer, replace that line with:

require __DIR__ . '/vendor/autoload.php';

2. Check for Namespace Changes

Newer versions of the Google API Client use PHP namespaces instead of the old underscore-prefixed class names. Try replacing Google_Client with the namespaced version:

$client = new Google\Client();

This is a common gotcha if you updated the API client but didn’t adjust your code to match the new namespace structure.

3. Verify File Paths & Permissions

Even if you see client.php exists, double-check:

  • The path in your autoloader include is correct (no typos in directory names, case sensitivity might matter on some setups even if you’re on Windows).
  • Your web server (XAMPP’s Apache) has read permissions for the apiclient directory and all its files. Sometimes file permissions get messed up after updating PHP or moving files.

4. Refresh Composer Autoloader (If Using Composer)

If you installed the API client via Composer, run this command in your project directory to regenerate the autoloader mapping—this fixes issues where PHP updates or dependency changes break class lookups:

composer dump-autoload

Try these steps one by one, starting with the autoloader fix—9 times out of 10 that’s the root cause. Let me know if any of these get you past the error!

内容的提问来源于stack exchange,提问作者joey

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:40:05