How to get user id after login using google oauth

I use Google oAuth to get user information through YoutubeAPI, but I donโ€™t know what I need to do after getting access_token to get user id, someone please help me.

+4
source share
3 answers

See the Google OAuth2 documentation on how to get registered user information.

Basically this is just a GET call https://www.googleapis.com/oauth2/v1/userinfo with the correct access token. The response includes a user ID.

Please note that you also need to include the correct scope in your first Google redirects:

 https://www.googleapis.com/auth/userinfo.profile 
+4
source

If you ask how to get either a YouTube username or a YouTube user ID for the current authenticated user, you can find it in the answer correctly authenticated for

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

+1
source

You can do one of the following:

  • perform a GET at www.googleapis.com/oauth2/v1/userinfo
  • decode the id_token that you will receive in the initial request using the JWT library

I would recommend the latter, since it is more reliable and does not require an additional call.

See this topic for more information: How to identify a Google OAuth2 user?

+1
source

Source: https://habr.com/ru/post/1437047/


All Articles