search

Home  >  Q&A  >  body text

IOS使用google+登陆提示 invalid_grant

公司的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了一天 也没解决,求指点

天蓬老师天蓬老师2772 days ago655

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 13:24:15

    Ah! Forgot, this problem has been solved by itself!
    I was misled by the official documentation. The Your server's OAuth 2.0 client ID in the document is the client id generated when creating ios application in the Google Developer Console.
    The problem lies in the incorrect redirecturi setting on the server side. The correct value is: $client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
    This parameter is fixed.

    I have written detailed information on my blog (still being sorted out.)

    reply
    0
  • Cancelreply