IOS使用google+登陆提示 invalid_grant

 小帅哥沈阳后援会果果 发布于 2022-11-05 08:09

公司的app允许使用google账号登陆。
为使服务器能使用已登录用户的google账号读取用户信息,使用了 https://developers.google.com/+/web/signin/server-side-flow 文中所说的one-time-code flow 方案。
参考官方文档 https://developers.google.com/+/mobile/ios/sign-in
向服务器发送serverCode (就是文中所指one-time-code)之后,服务端一直提示:

object(Google_AuthException)#27 (7) {
  ["message":protected]=>
  string(60) "Error fetching OAuth2 access token, message: 'invalid_grant'"
  ["string":"Exception":private]=>
  string(0) ""
  ["code":protected]=>
  int(400)
  ["file":protected]=>
  string(92) "/google-api-php-client-read-only/src/auth/Google_OAuth2.php"
... ...

我使用javascript重新实现one-time-code flow却成功了。

昨天google了一天 也没解决,求指点

1 个回答
  • 啊!忘记了,这个问题已经自行解决啦!
    被官方文档误导了。文档中的Your server's OAuth 2.0 client ID就是在Google开发者控制台中create ios application的时候生成的client id。
    问题出在服务端的redirecturi设置有误,正确的值是:$client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
    这个参数是固定的。

    详细的资料我写到自己的博客上了 (还在整理中。)

    2022-11-09 15:38 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有