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

2023-09-06 03:38:20 作者:丿丶Iceン爹爹

我正在开发使用GoogleAccountCredential登录,上传和放大器的模块;将文件下载到GoogleDrive。

I'm developing an module that use GoogleAccountCredential to login, upload & download a file to GoogleDrive.

我想获得用户至上,姓氏和谷歌帐户的头像上显示我的登录功能。

I want to get user first, last name and avatar of google account for display on my login feature.

我已经尝试

 GoogleAccountCredential.getAccountName()

但它仅返回帐户名。

But It return only account name.

和查看有关的OAuth 2.0 但不能肯定它可以提供我需要的。

And see about OAuth 2.0 but not sure It can provide which I needed.

不知道从哪里得到这些信息来源,任何建议还帮助我。这是要命的,如果有一些例子

Don't know where to get those infomation, any suggestion also help me. It's awsome if have some examples

推荐答案

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

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

您将获得

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

也有特定的语言工作codeS以下文档中:检索和使用OAuth 2.0凭证的。

玩得开心!