2015-01-22 1 views
0

Здравствуйте, я только начал изучать gplus-api signin с помощью javascript, но я столкнулся с ошибкой, которая говорит об этом Не удалось выполнить 'postMessage' в 'DOMWindow': Предполагаемое начало цели ('file: //') не соответствует началу окна получателя ('null'). Это мой код, который я назвал на этом сайте, но didn; t помогите мне! https://developers.google.com/+/web/signin/javascript-flowДает мне эту ошибку в gplus-api, используя JS

Мой код

<!DOCTYPE HTML> 
<html> 
    <head></head> 
<body> 
    <script src="https://apis.google.com/js/client:platform.js" async defer></script> 

    <meta name="google-signin-clientid" content="MY_CLIENT_ID.apps.googleusercontent.com"> 
    <meta name="google-signin-scope" content="https://www.googleapis.com/auth/plus.login" /> 
    <meta name="google-signin-requestvisibleactions" content="http://schema.org/AddAction" /> 
    <meta name="google-signin-cookiepolicy" content="single_host_origin" /> 

    <script type="text/javascript"> 
    (function(){ 
     var po = document.createElement('script'); 
     po.type = "text/javascript"; 
     po.async = true; 
     po.src = "https://apis.google.com/js/client:plusone.js"; 
     var s = document.getElementByTagName('script'); 
     s.parentNode.insertBefore(po,s); 
    }); 

function render() { 

    // Additional params including the callback, the rest of the params will 
    // come from the page-level configuration. 
    var additionalParams = { 
    'callback': signinCallback 
    }; 

    // Attach a click listener to a button to trigger the flow. 
    var signinButton = document.getElementById('signinButton'); 
    signinButton.addEventListener('click', function() { 
     gapi.auth.signIn(additionalParams); // Will use page level configuration 
    }); 
} 

    function signinCallback(authResult) { 
     if (authResult['status']['signed_in']) { 
    // Update the app to reflect a signed in user 
    // Hide the sign-in button now that the user is authorized, for example: 
     document.getElementById('signinButton').setAttribute('style',    'display: none'); 
    } else { 
    // Update the app to reflect a signed out user 
    // Possible error values: 
    // "user_signed_out" - User is signed-out 
    // "access_denied" - User denied access to your app 
    // "immediate_failed" - Could not automatically log in the user 
    console.log('Sign-in state: ' + authResult['error']); 
    } 
    } 
</script> 
    <button id="signinButton">Sign in with Google</button> 
    </body> 
    </html> 

мой JS происхождение http://localhost:8080, а также, когда я пытаюсь загрузить этот адрес он дает мне ошибку 404 Пожалуйста, помогите решить мне эту ошибку!

ответ

0

Вы должны запустить веб-сервер (даже локально) при работе с Google+ Войти Простой пример для запуска Python с портом, установленным в 8080:.

python -m SimpleHTTPServer 8080 

Вы также можете настроить/запустить Apache или другого сервера для локального тестирования.

Смежные вопросы