使用Google-登录Javascript时不调用data-onsuccess函数

The data-onsuccess function is not called when using Google-Sign in Javascript

我希望用户能够在他的网络浏览器中使用他的 Google 帐户登录。但是,没有调用 data-onsuccess 方法。

我上传了一个带有登录代码的 .html 文件到我的网站空间,创建了一个带有相关设置的 Google API 项目。我可以看到登录按钮。我可以单击它并输入我的 Google 帐户数据并允许我的应用程序访问我的帐户。但是,没有调用data-onsuccess方法,所以我无法对成功登录做出反应。

我尝试使用 Google 中的 umodified example code 和我自己的代码进行登录,我在代码中添加了一些调试以查看 JS 是否正常工作:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="google-signin-scope" content="profile email">
        <meta name="google-signin-client_id" content="CORRECT_VALUE_HERE.apps.googleusercontent.com">
        <script src="https://apis.google.com/js/platform.js" async defer></script>
        <title>Google sign in test</title>
    </head>
    <body>
        <h1>Google sign in test</h1>
        <div class="g-signin2" data-onsuccess="onSignIn"></div>
        <br>
        <a href="#" onclick="signOut();">Sign out</a>
        <br>
        <a href="index.html">Back</a>
        <br>
        <a href="#" onclick="someTest()">JavaScript Test</a>
        <br>
        <ul>
            <li id="gID">Google ID, temporary</li>
            <li id="gFullName">Full Name</li>
            <li id="gGivenName">Given Name</li>
            <li id="gFamilyName">FamilyName</li>
            <li id="gImg">Image URL</li>
            <li id="gEMail">E-Mail</li>
            <li id="gToken">Google Token, permanent</li>
        </ul>
        <script>
            function onSignIn(googleUser) {
                alert('in onSignIn');
                // Useful data for your client-side scripts:
                var profile = googleUser.getBasicProfile();
                document.getElementById('gID').textContent = profile.getId();
                document.getElementById('gFullName').textContent = profile.getName();
                document.getElementById('gGivenName').textContent = profile.getGivenName();
                document.getElementById('gFamilyName').textContent = profile.getFamilyName();
                document.getElementById('gImg').textContent = profile.getImageUrl();
                document.getElementById('gEMail').textContent = profile.getEmail();

                // The ID token you need to pass to your backend:
                var id_token = googleUser.getAuthResponse().id_token;
                document.getElementById('gToken').textContent = id_token;
            };
            function someTest() {
                alert('js is working');
                var x = {};
                x.getBasicProfile = function() {
                    var y = {};

                    y.getId = function() { return 'fake id'; };
                    y.getName = function() { return 'fake fake full name'; };
                    y.getGivenName = function() { return 'fake fake given name'; };
                    y.getFamilyName = function() { return 'fake fake family name'; };
                    y.getImageUrl = function() { return 'fake image'; };
                    y.getEmail = function() { return 'fake e-mail'; };

                    return y;
                };

                x.getAuthResponse = function() {
                    var z = {}

                    z.id_token = 'fake id token';

                    return z;
                };

                onSignIn(x);

            };
            function signOut() {
                var auth2 = gapi.auth2.getAuthInstance();
                auth2.signOut().then(function () {
                    console.log('User signed out.');
                });
            };
        </script>
    </body>
</html>

我在浏览器或 HTTP 服务器中没有看到任何错误消息。谁能告诉我我做错了什么?

我已经tried/checked:

我发现了问题:当用户在其浏览器中禁用了第 3 方 cookie 时,整个过程无法正常工作。