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

Google People API PHP开发:Google_Service_PeopleService类缺失求助

Fix: Class 'Google_Service_PeopleService' Not Found in Google People API PHP Quickstart

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

  1. Replace the class name in your code
    Swap out the line:

    $service = new Google_Service_PeopleService($client);
    

    With:

    $service = new Google_Service_People($client);
    
  2. Verify your library version
    To confirm you're on the latest compatible version, run this command in your project directory:

    composer show google/apiclient
    

    You should see a version >= 2.12.0 (where the class rename took effect). If not, update it with:

    composer update google/apiclient
    
  3. Double-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 vendor folder and composer.lock file, then re-run composer install to do a fresh, clean install.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 03:23:16