“immediate_failed” - Could not automatially log in the user

假如想象 提交于 2020-01-19 13:45:30

问题


I have a problem when I developed my website with Google+ sign-in: I did step by step that the doc told me but I always failed at step4: https://developers.google.com/+/web/signin/

the result was always ""immediate_failed" - Could not automatially log in the user", I just don't kown why, can anyone help me, thanks very much! :-(


回答1:


Note that in the sample code you pointed to, the "immediate_failed" check is commented out. This is intentional, since the first time a user encounters the Sign-in button on the page, it will fail.

The reason it fails is that when the page first loads, before the user even presses the button, a request is sent to Google to determine if the user has already logged in (via Google or another site, for example). If they are - there is no need for them to log in again, so the button never needs to be shown. But if they have not been logged in already, you will get the "immediate_failed" response, and will need to either show (or not clear) the button.

tl;dr - Don't worry aout getting immediate_failed when the page first loads. This is normal.




回答2:


As a workaround I use gapi.auth.authorize method in the gapi.auth.signIn callback. Here is my code:

gapi.auth.signIn({
    'callback': gPlusLoginCallback
});

function gPlusLoginCallback(authResult) {
    if (authResult['status']['signed_in']) {
        doSmth(authRes['access_token']); 
    } else if (authResult['error'] == "immediate_failed") {
        gapi.auth.authorize({
            client_id: gplusClientId,
            scope: 'https://www.googleapis.com/auth/plus.login email',
            immediate: true
        }, function (authRes) {
            if (authRes['status']['signed_in']) {
                doSmth(authRes['access_token']);
            }
        });
    }
}

function doSmth(accessToken){
    //Do smth
}



回答3:


Change this setting "immediate: true", to be false " immediate: false". But if you like to make more complex implementation look at the first sample here https://developers.google.com/api-client-library/javascript/start/start-js. You have to calls to Google's "gapi.auth.authorize({...", the first one with "immediate: true", and the second one with "immediate: false".




回答4:


The question is old but I faced this issue recently.

In my case, it was because I specified the URI parameter prompt to none. I guess Google doesn't like that if the user has never been logged to your platform before.

Whenever I changed that to consent or totally removed it, it worked great.



来源:https://stackoverflow.com/questions/15863349/immediate-failed-could-not-automatially-log-in-the-user

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!