使用google oauth登录后如何获取用户ID [英] How to get user id after login with google oauth

查看:33
本文介绍了使用google oauth登录后如何获取用户ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 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屋!

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