Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get user id after login with google oauth [duplicate]

I use Google oAuth to get user info via YoutubeAPI, but I don't know what I need to do after get access_token to retrieve userID, anybody please help me.

like image 333
Huy Tran Avatar asked Sep 30 '12 14:09

Huy Tran


3 Answers

See Google's OAuth2 documentation for how to get information about the logged in user.

It's basically just a GET call to https://www.googleapis.com/oauth2/v1/userinfo with a correct access token. In the response the user id is included.

Note that you also need to include the correct scope in your very first redirect to Google:

https://www.googleapis.com/auth/userinfo.profile
like image 93
Jan Gerlinger Avatar answered Sep 29 '22 22:09

Jan Gerlinger


If you're asking about how to get either the YouTube username or the YouTube user ID for the currently authenticated user, it can be found in the response to a properly authenticated request to

http://gdata.youtube.com/feeds/api/users/default?v=2

like image 36
Jeff Posnick Avatar answered Sep 29 '22 23:09

Jeff Posnick


You can do one of the following:

  1. perform a GET on www.googleapis.com/oauth2/v1/userinfo
  2. decode the id_token that you get in the initial request, using a JWT library

I'd recommend the latter as it is more robust and doesn't require an extra call.

See this thread for more info: How to identify a Google OAuth2 user?

like image 33
Ryan Shea Avatar answered Sep 29 '22 22:09

Ryan Shea