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

使用Google APIs PHP客户端库实现谷歌登录需保留的Composer服务

仅保留Google登录按钮认证所需的PHP客户端库服务

问题背景

我使用Google APIs Client Library for PHP实现「使用Google登录」按钮,通过Composer安装依赖后,发现库中包含了YouTube、Analytics等不需要的服务(占用约60MB空间)。根据库的README说明,可通过运行Google\Task\Composer::cleanup任务,在composer.json中指定需保留的服务来排除冗余依赖,现需确认仅实现登录认证功能需要保留哪些服务。

解决方案

仅实现Google登录的OAuth2认证功能,只需要保留Oauth2服务即可,核心客户端组件会被cleanup任务自动保留,无需额外指定。

具体操作步骤

  • 修改composer.json,添加extra字段指定要保留的服务:

    {
      "require": {
        "google/apiclient": "^2.0"
      },
      "extra": {
        "google/apiclient-services": [
          "Oauth2"
        ]
      }
    }
    
  • 运行cleanup任务移除冗余服务:

    composer exec google-task-cleanup
    

    或者执行Composer的更新后脚本(如果之前已配置):

    composer run-script post-update-cmd
    

执行完成后,客户端库就只会保留Oauth2认证相关的文件,其余冗余服务会被移除,大幅减小依赖体积。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 18:21:03