我想使用 ux_mode:redirect 而不是默认的 popup 方法来使用javascript登录google。当前登录发生在下面,
Dim currentMonth As Integer
Dim yearMonthAgo As Integer ' if today is January then it will be previous year
Dim previousMonth As Integer
previousMonth = DatePart(DateInterval.Month, DateAdd(DateInterval.Month, -1, Today))
yearMonthAgo = DatePart(DateInterval.Year, DateAdd(DateInterval.Month, -1, Today))
currentMonth = DatePart(DateInterval.Month, DateAdd(DateInterval.Month, 0, Today))
Response.Write("First day of previous month is: " & DateAdd(DateInterval.Day, 0, DateValue(previousMonth.ToString & "/1/" & yearMonthAgo.ToString())))
Response.Write("<br />")
Response.Write("Last day of previous month is: " & DateAdd(DateInterval.Day, -1, DateValue(currentMonth.ToString & "/1/" & yearMonthAgo.ToString())))
其中 glogin 是我用于Google登录的img的ID。
<script src="https://apis.google.com/js/platform.js?onload=onLoadGoogleCallback" async defer></script>
<script>
function onLoadGoogleCallback(){
element = document.getElementById('glogin');
//console.log(element);
gapi.load('auth2', function() {
auth2 = gapi.auth2.init({
client_id: 'CLIENT_ID.apps.googleusercontent.com',
cookiepolicy: 'single_host_origin',
scope: 'profile',
//ux_mode : 'redirect'
});
auth2.attachClickHandler(element, {},
function(googleUser) {
console.log('Signed in: ' + googleUser.getBasicProfile().getName());
var profile = googleUser.getBasicProfile();
console.log('Name: ' + profile.getName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail());
},
function(error) {
console.log('Sign-in error', error);
}
);
});
}
</script>
这工作正常,我正在控制台中获取信息。但是,如果我尝试使用重定向方法,控制台中将不会显示任何内容。登录后我该如何使用 auth2.attachClickHandler(...)来获取信息?