React Native谷歌登录报错:离线访问需配置Server Web ClientID
解决RNGoogleSignin离线访问缺少web ClientID错误
问题场景
已在Firebase集成Google和Facebook登录,但启动应用时触发错误:
Error: RNGoogleSignin: offline use requires server web ClientID, js engine: hermes
错误来自@react-native-google-signin模块的GoogleSignin.ts文件,触发代码逻辑如下:
configure(options: ConfigureParams = {}): void { if (options.offlineAccess && !options.webClientId) { throw new Error('RNGoogleSignin: offline use requires server web ClientID'); } }
错误原因
模块配置逻辑强制要求:当开启offlineAccess(用于获取刷新令牌,支持离线访问Google API)时,必须同时提供web客户端ID,否则直接抛出错误。
解决方案
方案1:保留离线访问,补充webClientId
从你提供的google-services.json中,找到oauth_client数组里client_type: 3对应的client_id,这就是需要的web客户端ID:
969785011148-hq119bljaie8f0g4albl1mqsqj98d3sl.apps.googleusercontent.com
在配置GoogleSignin时同时传入两个参数:
import { GoogleSigninSingleton } from '@react-native-google-signin/google-signin'; GoogleSigninSingleton.configure({ offlineAccess: true, webClientId: '969785011148-hq119bljaie8f0g4albl1mqsqj98d3sl.apps.googleusercontent.com', // 其他原有配置参数... });
方案2:关闭离线访问
如果你不需要离线访问功能,直接移除offlineAccess配置(默认值为false),或者显式设置为false即可,无需传入webClientId:
import { GoogleSigninSingleton } from '@react-native-google-signin/google-signin'; GoogleSigninSingleton.configure({ offlineAccess: false, // 其他原有配置参数... });
内容的提问来源于stack exchange,提问作者Rohan Patil
相关产品推荐
相关产品推荐

