Я пытаюсь сделать это: https://developers.google.com/identity/sign-in/web/sign-in Итак, в свой index.html я добавил следующее:
<script src="https://apis.google.com/js/platform.js" async defer></script>
<meta name="google-signin-client_id" content="changedkey.apps.googleusercontent.com ">
На login.html я пытался использовать это:
<div class="g-signin2" data-onsuccess="onSignIn"></div>
А еще это:
<div id="my-signin2">Google </div>
<script>
function onSuccess(googleUser) {
console.log('Logged in as: ' + googleUser.getBasicProfile().getName());
}
function onFailure(error) {
console.log(error);
}
function renderButton() {
gapi.signin2.render('my-signin2', {
'scope': 'profile email',
'width': 240,
'height': 50,
'longtitle': true,
'theme': 'dark',
'onsuccess': onSuccess,
'onfailure': onFailure
});
}
</script>
Но они оба не работают, а я нажимаю кнопку и ничего не происходит. Что я сделал не так?
РЕДАКТИРОВАТЬ: я изменил код, чтобы он выглядел так:
<script>
var googleUser = {};
var startApp = function() {
gapi.load('auth2', function(){
// Retrieve the singleton for the GoogleAuth library and set up the client.
auth2 = gapi.auth2.init({
client_id: 'MYKEY.apps.googleusercontent.com',
cookiepolicy: 'single_host_origin',
// Request scopes in addition to 'profile' and 'email'
//scope: 'additional_scope'
});
attachSignin(document.getElementById('google'));
});
};
function attachSignin(element) {
console.log(element.id);
auth2.attachClickHandler(element, {},
function(googleUser) {
document.getElementById('name').innerText = "Signed in: " +
googleUser.getBasicProfile().getName();
}, function(error) {
alert(JSON.stringify(error, undefined, 2));
});
}
</script>
И такая кнопка:
<div id="google" type="button"><img src="assets/login/google-logo.png"><span class="google-title">GOOGLE</span></div>
И он входит в функцию, создает окно для входа в Google, но ВСЕГДА возвращает обратно всплывающее окно с надписью: «ошибка»: «popup_closed_by_user» Почему это происходит? Также я получаю это в консоли: s3.amazonaws.com/uploads.hipchat.com/39260/829560/nGKpPpPQ1vlvC27/upload.png