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

遇到GooglePlusAPIError:需启用Legacy People API,求解决方案

解决Google OAuth2.0认证时的Legacy People API报错问题

问题原因

报错明确指出你的Google Cloud项目未启用Legacy People API,这是因为passport-google-oauth20策略默认会调用该旧版API获取用户信息,而你的项目要么从未使用过它,要么已经禁用。

解决方案

方案1:启用Legacy People API

  • 登录Google Cloud控制台,定位到项目ID为297453248242的项目
  • 进入API库,搜索“Legacy People API”
  • 点击启用该API,等待5-10分钟让系统同步配置后重新测试认证流程

方案2:修改Passport策略配置(推荐,避免依赖旧API)

passport-google-oauth20默认依赖旧API,我们可以通过指定新的用户信息端点来绕过这个问题,具体操作如下:

在你的Passport策略配置文件(比如passport-config.js)中,添加userProfileURL字段,指向Google OAuth2的v3用户信息接口:

const GoogleStrategy = require('passport-google-oauth20').Strategy;
const passport = require('passport');

passport.use(new GoogleStrategy({
    clientID: '你的Google客户端ID',
    clientSecret: '你的Google客户端密钥',
    callbackURL: '/auth/google/redirected',
    // 指定新的用户信息端点,替代旧的Legacy People API
    userProfileURL: 'https://www.googleapis.com/oauth2/v3/userinfo'
}, (accessToken, refreshToken, profile, done) => {
    // 这里处理用户信息的存储或关联逻辑
    return done(null, profile);
}));

修改后,你的路由代码无需调整,passport-google-oauth20会通过新的端点获取用户邮箱等信息,不再调用Legacy People API,也就不需要启用该旧API了。

注意事项

方案1只是临时解决办法,Legacy People API属于旧版服务,未来可能被Google停用;方案2使用官方推荐的OAuth2 v3接口,兼容性和稳定性更强,建议优先采用。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 14:50:21