javascript - 在使用 ux_mode 时获取用户信息:'redirect' 使用自定义图像进行 google 登录
问题描述
我想使用ux_mode:redirect而不是使用 javascript 进行 google 登录的默认弹出方法。目前登录发生如下,
<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>
其中glogin是我用于 google 登录的 img 的 id。
<img src="./img/login-g.jpg" id="glogin" >
这工作正常,我在控制台中获取信息。但是如果我尝试重定向方法,控制台中不会显示任何内容。登录后我用什么代替 auth2.attachClickHandler(...)来获取信息?
解决方案
推荐阅读
- ios - 你如何为 iOS DatePicker Xamarin 制作自定义渲染器
- amazon-web-services - 如何正确使用安全组内的 VpcId 属性?
- javascript - 如何在Angular的嵌套地图函数中收集每个用户的所有响应?
- python - 使用 PostGIS 查找最近点
- java - 即使在 Android 上的权限被拒绝时,应用程序也会将文件下载到存储中
- javascript - 如何更改此对象属性分配以避免原型污染
- git - 撤消 git reset --hard,怎么做?
- windows - 由于路径无效而无法签出新分支?
- oracle - Oracle Reports Builder 12 多页报表
- java - gRPC 连接循环