这里我试图获取用户信息,如用户名,名字等。使用Google authe2
,以下是代码
如果我点击
<a href='#' onclick='login();' id="login" '> Click here to login </a> {onclick='login()'}
登录按钮,我正在获取访问令牌,但它会阻止并显示如下错误:
错误:访问属性&#34;文档&#34;
的权限被拒绝
并且弹出窗口没有关闭。 请帮我解决这个问题
var OAUTHURL = 'https://accounts.google.com/o/oauth2/auth?';
var VALIDURL = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=';
var SCOPE = 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email';
var CLIENTID = '{MY CLIENT ID}';
var REDIRECT = '{My redirection URL}'
var LOGOUT = 'http://accounts.google.com/Logout';
var TYPE = 'token';
var _url = OAUTHURL + 'scope=' + SCOPE + '&client_id=' + CLIENTID + '&redirect_uri=' + REDIRECT + '&response_type=' + TYPE;
var acToken;
var tokenType;
var expiresIn;
var user;
var loggedIn = false;
function login() {
var win = window.open(_url, "windowname", 'width=600, height=600');
var pollTimer = window.setInterval(function () {
try {
console.log(win.document.URL);
if (win.document.URL.indexOf(REDIRECT) != -1) {
window.clearInterval(pollTimer);
var url = win.document.URL;
acToken = gup(url, 'access_token');
tokenType = gup(url, 'token_type');
expiresIn = gup(url, 'expires_in');
win.close();
validateToken(acToken);
}
} catch (e) {
alert(e);
}
}, 500);
}