Abd*_*man 9 javascript google-plus google-signin
您好我正在使用google api登录我的网络应用程序.现在它的工作正常.但问题是当我进入登录页面时,sigin会自动启动.但我不希望这样.我希望用户先单击"登录"按钮,然后该过程将开始.
我正在使用下面的按钮
<div class="g-signin2" data-onsuccess="onSignIn"></div>
Run Code Online (Sandbox Code Playgroud)
和 谷歌登录参考.
使用“attachClickHandler”启动 Google 登录。
<script src="https://apis.google.com/js/client:platform.js?onload=init" async defer></script>
<script>
function init() {
gapi.load('auth2', function() {
auth2 = gapi.auth2.init({
client_id: '*************.apps.googleusercontent.com',
cookiepolicy: 'single_host_origin',
scope: 'profile email'
});
element = document.getElementById('glogin');
auth2.attachClickHandler(element, {}, onSignUp, onFailure);
});
}
function onSignUp(googleUser) {
var profile = googleUser.getBasicProfile();
}
</script>
Run Code Online (Sandbox Code Playgroud)
据我所知,最好的方法是使用 Java 脚本登录 google。
\n\n使用
\n\nscript type="text/javascript">\n (function() {\n var po = document.createElement(\'script\'); po.type = \'text/javascript\'; po.async = true;\n po.src = \'https://apis.google.com/js/client.js?onload=onLoadCallback\';\n var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(po, s);\n })();\n</script>\nRun Code Online (Sandbox Code Playgroud)\n\n初始化 js 。最后调用下面的方法来登录用户
\n\nfunction login() \n{\n\xc2\xa0\xc2\xa0var myParams = {\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\'clientid\' : \'YOUR_CLIENT_ID.apps.googleusercontent.com\', //You need to set client id\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\'cookiepolicy\' : \'single_host_origin\',\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\'callback\' : \'loginCallback\', //callback function\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\'approvalprompt\':\'force\',\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\'scope\' : \'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.profile.emails.read\'\n\xc2\xa0\xc2\xa0};\n\xc2\xa0\xc2\xa0gapi.auth.signIn(myParams);\n}\nRun Code Online (Sandbox Code Playgroud)\n\n通过使用这个我能够解决这个问题。现在用户需要点击登录才能登录
\n