且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从谷歌账户获取用户名、头像

更新时间:2023-02-25 11:59:47

ianhanniballake 的答案有效,但有更好的方法.您无需登录 Google+ 即可获取用户信息.

ianhanniballake's answer works, but there is a better way to do it. You don't need Google+ sign in to get user info.

授权范围https://www.googleapis.com/auth/userinfo.profile

https://www.googleapis.com/oauth2/v1/userinfo?alt=json 发出 GET 请求

你会得到

{
 "id": "xx",
 "name": "xx",
 "given_name": "xx",
 "family_name": "xx",
 "link": "xx",
 "picture": "xx",
 "gender": "xx",
 "locale": "xx"
}

以下文档中还有特定于语言的工作代码:检索和使用 OAuth 2.0 凭据.

There are also language specific working codes in the following documentation: Retrieving and Using OAuth 2.0 Credentials.

玩得开心!