Google People API PHP开发:Google_Service_PeopleService类缺失求助
Hey there, this is a super common issue caused by a version mismatch between the official tutorial and the latest Google PHP Client Library—let's break it down and fix it:
Why This Happens
Google renamed the service class for the People API in a recent update to their PHP client library. The older tutorial still references the deprecated Google_Service_PeopleService class, but the current version of the library uses Google_Service_People instead.
Step-by-Step Fix
Replace the class name in your code
Swap out the line:$service = new Google_Service_PeopleService($client);With:
$service = new Google_Service_People($client);Verify your library version
To confirm you're on the latest compatible version, run this command in your project directory:composer show google/apiclientYou should see a version >= 2.12.0 (where the class rename took effect). If not, update it with:
composer update google/apiclientDouble-check method calls
Good news—most core API methods haven't changed! For example, fetching the authenticated user's profile still works like this:$profile = $service->people->get('people/me', ['personFields' => 'names,emailAddresses']);
Extra Troubleshooting
- Make sure you're correctly including the Composer autoloader at the top of your script:
require __DIR__ . '/vendor/autoload.php'; - If you still see errors, delete your
vendorfolder andcomposer.lockfile, then re-runcomposer installto do a fresh, clean install.
内容的提问来源于stack exchange,提问作者georgewoofbates

