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

Android:Google登录客户端始终返回RESULT_CANCELED问题排查

解决Google登录返回RESULT_CANCELED问题

核心问题

你犯了一个关键错误:代码里setServerClientId()传入的是Android类型的客户端ID,但这个方法明确要求使用Web应用类型的客户端ID——代码注释里已经写了// Your server's client ID, not your Android client ID.,你没注意到这一点。

修正步骤

  • 打开Google Cloud控制台,找到你创建的「Web应用」类型OAuth客户端ID
  • 修改strings.xml中的web_client_id值,替换为这个Web应用的客户端ID
  • 重新编译并运行应用

额外验证项

  • 再次用gradle signingreport命令核对Android客户端ID对应的SHA-1签名,确保和当前应用的签名一致
  • 确认Android客户端ID和Web应用客户端ID属于同一个Google Cloud项目

修正后的关键代码片段

.setGoogleIdTokenRequestOptions(BeginSignInRequest.GoogleIdTokenRequestOptions.builder()
        .setSupported(true)
        // 这里要传入Web应用类型的客户端ID
        .setServerClientId(getString(R.string.web_client_id))
        .setFilterByAuthorizedAccounts(false)
        .build())

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 23:35:27