Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get user name, avatar from google account

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.

I've try

 GoogleAccountCredential.getAccountName()

But It return only account name.

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

like image 357
Tai Dao Avatar asked Jul 28 '13 04:07

Tai Dao


1 Answers

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

Authorize with scope https://www.googleapis.com/auth/userinfo.profile

Make GET request to https://www.googleapis.com/oauth2/v1/userinfo?alt=json

You will get

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

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

Have fun!

like image 92
JunYoung Gwak Avatar answered Oct 05 '22 13:10

JunYoung Gwak