Jak*_*oes 8 logout google-plus
我需要一些关于如何使用您的Google+帐户登录的网站创建退出功能的帮助.
文档说明您应该使用gapi.auth.signOut函数
https://developers.google.com/+/web/signin/sign-out
但作为javascript的新手我似乎没有任何运气.
这是我的代码 - 注销功能是底部的部分.我究竟做错了什么?
<script>
function signinCallback(authResult) {
if (authResult['status']['signed_in']) {
// Update the app to reflect a signed in user
// Hide the sign-in button now that the user is authorized, for example:
document.getElementById('signinButton').setAttribute('style','display: none ');
document.getElementById('callback').setAttribute('style','height: 100px;background-color: red ');
var mydiv = document.getElementById("callback");
var aTag = document.createElement('a');
aTag.innerHTML = "Sign out";
aTag.id= "signout";
mydiv.appendChild(aTag);
/*function checkid(){
document.getElementById('signout')
}*/
} else {
// Update the app to reflect a signed out user
// Possible error values:
// "user_signed_out" - User is signed-out
// "access_denied" - User denied access to your app
// "immediate_failed" - Could not automatically log in the user
console.log('Sign-in state: ' + authResult['error']);
}
}
document.addEventListener('DOMContentLoaded', function () {
document.getElementById("signout").addEventListener('click', function(){
gapi.auth.signOut();
});
</script>
Run Code Online (Sandbox Code Playgroud)
如果您希望要求您的用户重新输入凭据,则需要撤消用户对您的应用程序的身份验证.在我的应用程序中,我做了它像下面的代码片段.您可能会发现此答案很有用.
var token = gapi.auth.getToken();
if (token) {
var accessToken = gapi.auth.getToken().access_token;
if (accessToken) {
// make http get request towards: 'https://accounts.google.com/o/oauth2/revoke?token=' + accessToken
// In angular you can do it like this:
// $http({
// method: 'GET',
// url: 'https://accounts.google.com/o/oauth2/revoke?token=' + accessToken
// });
}
}
gapi.auth.setToken(null);
gapi.auth.signOut();Run Code Online (Sandbox Code Playgroud)
以下命令非常适合我。
gapi.auth2.getAuthInstance().disconnect();
Run Code Online (Sandbox Code Playgroud)
我的朋友用 jquery 做了这个 - 而且效果很好。
$('#signout').on('click', function(event) {
gapi.auth.signOut();
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16472 次 |
| 最近记录: |