从谷歌账户获取用户名、头像 [英] Get user name, avatar from google account

查看:26
本文介绍了从谷歌账户获取用户名、头像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用 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()

但它只返回帐户名.

看看 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

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.

玩得开心!

这篇关于从谷歌账户获取用户名、头像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆