如何通过API检查用户是否登录了他的谷歌账户? [英] How to check whether a user is logged into his google account through API?
问题描述
我正在开发一个页面来显示用户可以访问的文档的预览.
I am developing a page to show preview of documents accessible to a user.
为了预览,我使用的是 src = https://docs.google.com/viewer?authuser=0&srcid={文档ID}
For previewing I am using an Iframe with src = https://docs.google.com/viewer?authuser=0&srcid={a document id}
这里的问题是,当用户未登录时,它会显示一个空白 iframe.
The problem here is that when the user is not logged in it shows a blank iframe.
如果当前用户未登录,我想将用户重定向到 google 登录页面,然后显示预览文档的页面.
I want to redirect the user to google login page if the current user is not logged in and then display the page previewing the document.
对于这个功能,我必须首先检查用户是否使用谷歌登录.
For this functionality I will have to check first that whether the user is logged in with google or not.
我认为谷歌在 iframe 的情况下施加了一些限制,因此它不会重定向到登录页面.
I think google has some restrictions imposed in case of iframe so it not redirecting to the login page.
如何通过API实现?
推荐答案
如果您使用 App Engine,请这样做:
If you use App Engine do it like this:
要查看显示 google 文档的页面,您必须已经在检查您是否已登录.
To view the page which is showing the google doc must already be checking if you are logged in.
只需配置 Google 用户 API.一切都在这里描述:
Just configure the Google Users-API. Everything is described here:
https://developers.google.com/appengine/docs/java/用户/概述
并在web.xml中设置安全约束https://developers.google.com/appengine/docs/java/config/webxml#Security_and_Authentication
And set the security constraints in web.xml https://developers.google.com/appengine/docs/java/config/webxml#Security_and_Authentication
<security-constraint>
<web-resource-collection>
<url-pattern>/page_shows_google_doc</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>*</role-name>
</auth-constraint>
</security-constraint>
这篇关于如何通过API检查用户是否登录了他的谷歌账户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!