使用 google oauth2 获取用户个人资料
我试图在使用 google-oauth2 登录时获取用户个人资料信息。用户成功登录,我可以获得 access_token 并可以在需要时刷新令牌。 尽管我阅读了文档并尝试了几个小时,但仍无法获取有关用户的任何信息。
来自开发者指南的“检索个人资料”部分:
https://www.google.com/m8/feeds/profiles/domain/domainName/full
应该就足够了。我尝试过使用“gmail.com”、“google.com”、“gmail”、“google”、“orkut”、“orkut.com”、myregisteredappsdomainname(和 .com)作为域名。我也尝试过,
https://www.google.com/m8/feeds/profiles/domain/domainName/full?access_token=access_token_for_user
我得到的只是 401 错误,其中显示“这是一个错误。”。关于401错误,我刷新了令牌并使用新令牌再次尝试,但不断收到401。
如何在登录时获取用户的个人资料信息和图像地址?
I'm trying to get user profile information upon logging in with google-oauth2. User successfully logs in and i can get the access_token and can refresh the token when needed.
Though i could not manage to get any information about the user despite reading the docs and trying for hours.
From "Retrieving profiles" section of developers guide :
https://www.google.com/m8/feeds/profiles/domain/domainName/full
should be enough. i've tried with "gmail.com", "google.com", "gmail", "google", "orkut", "orkut.com" , myregisteredappsdomainname (and .com) as domainName. i've also tried it with
https://www.google.com/m8/feeds/profiles/domain/domainName/full?access_token=access_token_for_user
all i managed to get was 401 error, where it says "That’s an error.". Regarding 401 error, I've refreshed the token and tried again with new token, but kept getting 401s.
How can i get profile information and image address for user upon logging in?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您要查找的范围是:
此处已经回答了这个问题
The scope you're looking for is:
This has been already answered here
即使在正确定义范围并获取访问令牌等之后,我在请求配置文件时也会遇到类似的错误。对我来说,技巧是在我的请求中包含 API 版本。请参阅此处了解详细信息 http://code.google.com/googleapps/域/profiles/developers_guide.html#版本控制
I was getting similar errors requesting profiles even after correctly defining the scope and getting access tokens etc.. The trick for me was to include the API version on my requests. See here for more info http://code.google.com/googleapps/domain/profiles/developers_guide.html#Versioning
也许有点晚了,但这对某人有帮助吗?下面是我编写的用于获取 gplus 用户配置文件的工作代码
在 HTML 中,下面的标记将显示 goolge 登录按钮
下面是 java 脚本
请确保您在 body 标记内异步加载 google api javascript,如下所示
要处理注销,请参阅答案我在下面的链接中提供,您需要将 access_token 存储在后端,以便在注销调用期间使用它,在我的情况下,我已存储在会话中并通过 ajax 调用
gapi.auth.signOut();不工作我迷路了
Maybe little late yet could this be helpful to someone. Below is the working code I wrote to get gplus user profile
In HTML below markup will display goolge signIn button
Below is the java script
Please make sure that you load google api javascript asynchronously within the body tag as below
To handle logout refer to the answer I provide in below link, you will need to store access_token in backend so that during logout call this to be used, in my case I have stored in session and getting through ajax call
gapi.auth.signOut(); not working I'm lost
嘿,你为什么不看看下面给出的代码:
http://www.codeproject.com/KB/aspnet/OAuth4Client.aspx
它绝对对你有帮助。该项目实际上是一个 oauth 游乐场,用于将正确的 oauth 标头发送到正确的端点。
Hey why don't you look at the code given at:
http://www.codeproject.com/KB/aspnet/OAuth4Client.aspx
It definitely helps you. The project is actually an oauth playground to send correct oauth header to correct endpoints.