使用google oauth登录后如何获取用户ID [英] How to get user id after login with google oauth
问题描述
我使用 Google oAuth 通过 YoutubeAPI 获取用户信息,但在获取 access_token
以检索用户 ID 后我不知道我需要做什么,请帮助我.
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.
推荐答案
请参阅 Google 的 OAuth2 文档 如何获取登录用户的信息.
See Google's OAuth2 documentation for how to get information about the logged in user.
基本上只是使用正确的访问令牌对 https://www.googleapis.com/oauth2/v1/userinfo
进行 GET 调用.在响应中包含用户 ID.
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.
请注意,您还需要在第一次重定向到 Google 时包含正确的范围:
Note that you also need to include the correct scope in your very first redirect to Google:
https://www.googleapis.com/auth/userinfo.profile
这篇关于使用google oauth登录后如何获取用户ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!