Retrieving date of birth with Google OAuth API

梦想与她 提交于 2019-12-30 08:14:48

问题


Does any one know how to retrive D.O.B through Google OAuth api? I am able to get other information like name, email, gender by setting the scope as https://www.googleapis.com/auth/userinfo.profile. But I am not able to get D.O.B with this scope.


回答1:


I definitely get it for my account:

{
  "id": "108635752367054807758",
  "name": "Nicolas Garnier",
  "given_name": "Nicolas",
  "family_name": "Garnier",
  "link": "https://plus.google.com/108635752367054807758",
  "picture": "https://lh4.googleusercontent.com/-K1xGP8W20xk/AAAAAAAAAAI/AAAAAAAABhY/Cs_4qr30MxI/photo.jpg",
  "gender": "male",
  "birthday": "0000-08-25",
  "locale": "en"
}

all I did is authorize for the https://www.googleapis.com/auth/userinfo.profile scope and then sent a GET request to https://www.googleapis.com/oauth2/v2/userinfo

First make sure that the Google+ account that you are testing with has set a Birthday (of course), then try the request on the OAuth 2.0 Playground for instance: https://code.google.com/oauthplayground/#step1&apisSelect=https%3A//www.googleapis.com/auth/userinfo.profile&url=https%3A//www.googleapis.com/oauth2/v2/userinfo




回答2:


It seems you have to send 2 requests:

  • https://www.googleapis.com/plus/v1/people/me (oauth v1)
  • https://www.googleapis.com/oauth2/v2/userinfo (oauth v2)

to get both google plus profile data and google account data (there are date of birthday and also locale if you need it)

I use scribes and it works ok. Set two scopes ("https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/plus.me") and send two requests for both REST links



来源:https://stackoverflow.com/questions/10849148/retrieving-date-of-birth-with-google-oauth-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!