javascript 检测网络用户当前是否登录 Google?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4202785/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 10:41:11  来源:igfitidea点击:

Detect if a web user is currently logged in Google?

javascriptauthentication

提问by Cristiano Paris

Suppose I want to display certain content only if I know the user coming to my website has a valid Google Account and it's logged into that account.

假设我只想在知道访问我网站的用户拥有有效的 Google 帐户并且登录到该帐户时才显示某些内容。

Is there any way to do this in Javascript? I know that the Facebook API provides ways to tell the status of a user (logged in Facebook) and I'm sure I've seen sites doing this with Google Accounts as well, but searching for the relevant terms in Google leads me to nowhere as the search terms are poorly focused.

有没有办法在 Javascript 中做到这一点?我知道 Facebook API 提供了告诉用户状态(已登录 Facebook)的方法,我确定我也看到过使用 Google 帐户执行此操作的网站,但是在 Google 中搜索相关术语会让我无处可去因为搜索词没有重点关注。

Thank you for any help.

感谢您的任何帮助。

回答by Kevin

This blog claims to have done it, via checking for image return values linked to the social platforms provided by G+ / twitter / etc

这个博客声称已经做到了,通过检查链接到 G+ / twitter / 等提供的社交平台的图像返回值

http://www.tomanthony.co.uk/blog/detect-visitor-social-networks/

http://www.tomanthony.co.uk/blog/detect-visitor-social-networks/

<img style="display:none;"
onload="show_login_status('Google', true)"
onerror="show_login_status('Google', false)"
src="https://accounts.google.com/CheckCookie?continue=https%3A%2F%2Fwww.google.com%2Fintl%2Fen%2Fimages%2Flogos%2Faccounts_logo.png&followup=https%3A%2F%2Fwww.google.com%2Fintl%2Fen%2Fimages%2Flogos%2Faccounts_logo.png&chtml=LoginDoneHtml&checkedDomains=youtube&checkConnection=youtube%3A291%3A1"
/>

回答by Jesse Kemper

<script type="text/javascript">
function show_login_status(network, status){

    if(status == false){
        alert('NOT LOGGED IN');
    }
    if(status == true){
        alert('Logged In');
    }


}


</script>

<img style="display:none;"
onload="show_login_status('Google', true)"
onerror="show_login_status('Google', false)"
src="https://accounts.google.com/CheckCookie?continue=https%3A%2F%2Fwww.google.com%2Fintl%2Fen%2Fimages%2Flogos%2Faccounts_logo.png&followup=https%3A%2F%2Fwww.google.com%2Fintl%2Fen%2Fimages%2Flogos%2Faccounts_logo.png&chtml=LoginDoneHtml&checkedDomains=youtube&checkConnection=youtube%3A291%3A1"
/>

This will work.

这将起作用。