Google signin 在请求附加范围时,如何使用Google登录跳过“选择帐户”弹出窗口

Google signin 在请求附加范围时,如何使用Google登录跳过“选择帐户”弹出窗口,google-signin,google-oauth,googlesigninapi,Google Signin,Google Oauth,Googlesigninapi,我已经为web per集成了Google登录。 用户使用下面的测试代码登录后,调用addScope()会在请求其他作用域时触发Choose Account弹出窗口。如何跳过“选择帐户”并使用当前登录的用户帐户?我尝试将字段“user\u id”和“login\u hint”添加到grant()配置对象中,但没有成功 <script src="https://apis.google.com/js/platform.js"></script> <div class="g

我已经为web per集成了Google登录。 用户使用下面的测试代码登录后,调用addScope()会在请求其他作用域时触发Choose Account弹出窗口。如何跳过“选择帐户”并使用当前登录的用户帐户?我尝试将字段“user\u id”和“login\u hint”添加到grant()配置对象中,但没有成功

<script src="https://apis.google.com/js/platform.js"></script>
<div class="g-signin2" data-onsuccess="onSignIn" data-theme="dark"></div>


function initClient() {
    gapi.load('auth2', function () {
        gapi.auth2.init({
            client_id: 'CLIENT_ID.apps.googleusercontent.com',
            fetch_basic_profile: true
        });
    });
};

function onSignIn(googleUser) {
    var profile = googleUser.getBasicProfile();
    console.log("ID: " + profile.getId());
    console.log("Email: " + profile.getEmail());

    addScope();
}

function addScope() {
    var options = new gapi.auth2.SigninOptionsBuilder({ 'scope': 'email https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/contacts.readonly' });
    var auth2 = gapi.auth2.getAuthInstance();
    var googleUser = auth2.currentUser.get();
    googleUser.grant(options).then(
        function (success) {
            console.log(JSON.stringify({ message: "success", value: success }));
        },
        function (fail) {
            alert(JSON.stringify({ message: "fail", value: fail }));
        });
}

initClient();

函数initClient(){
加载('auth2',函数(){
gapi.auth2.init({
client_id:'client_id.apps.googleusercontent.com',
获取基本配置文件:true
});
});
};
函数onSignIn(谷歌用户){
var profile=googleUser.getBasicProfile();
log(“ID:+profile.getId());
log(“Email:+profile.getEmail());
addScope();
}
函数addScope(){
var options=new gapi.auth2.SigninOptionsBuilder({'scope':'emailhttps://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/contacts.readonly' });
var auth2=gapi.auth2.getAuthInstance();
var googleUser=auth2.currentUser.get();
googleUser.grant(选项),然后(
功能(成功){
log(JSON.stringify({message:“success”,value:success}));
},
功能(失败){
警报(JSON.stringify({message:“fail”,value:fail}));
});
}
initClient();

不建议这样做,但您可以这样做:

this.auth2.signIn({ "prompt": "none" }).then(

请参见

这对我不起作用,显然,
GoogleUser.grant(options)
方法采用与
This.auth2.signIn()方法相同的options对象。将选项设置为
{“prompt”:“none”}
对这两种方法都不起作用。对于避免“选择用户”对话框,您还有其他想法吗?