IOS使用google+登陆提示 invalid_grant
天蓬老师
天蓬老师 2017-04-17 13:22:15
[iOS讨论组]

公司的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)
PHP中文网

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

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

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号