未捕获的gapi.auth2.ExternallyVisibleError:无效的cookiePolicy,未捕获的错误:在Electron中侦听EADDRINUSE ::: 8070

时间:2019-03-14 02:03:39

标签: node.js oauth electron

我试图通过OAuth2.0在Google中以电子方式登录Google

我读了这篇评论,所以我也做了server.js

  

Google登录API仅在运行中的Web服务器上起作用。

这些我开始一个项目时遇到的错误

  1. 节点server.js
  2. npm开始
  

未捕获的错误:收听EADDRINUSE ::: 8070未捕获的uO {消息:   “无效的cookiePolicy”,堆栈:“ gapi.auth2.ExternallyVisibleError:   无效的cookieP…pis.google.com / js / platform.js?onload = init:18:356)“}

     

未捕获的错误:监听EADDRINUSE ::: 8070

server.js

console.log("server start")
var http = require('http');

//create a server object:
var server =http.createServer(function (req, res) {
    res.write('Hello World!'); //write a response to the client
    res.end('test'); //end the response
}).listen(8070); //the server object listens on port 8080
server.on('listening',function(){
    console.log('ok, server is running');
});

index.html

<script>
      var gauth;
     function checkLoginStatus() {
        var loginBtn = document.querySelector('#loginBtn');
        var nameTxt = document.querySelector('#name');

        if (gauth.isSignedIn.get()) {
            console.log("logined");
            loginBtn.value = 'Logout'
            var profile=gauth.currentUser.get().getBasicProfile();
            nameTxt.innerHTML='Welcome <strong>'+profile.getName()+'</strong'
        }
        else {
            console.log("loged out");
            loginBtn.value = 'Login'
            nameTxt.innerHTML='';
        }
    }
    function init() {
        console.log("init")
        gapi.load('auth2', function () {
            console.log("auth2");

            gauth = gapi.auth2.init(
                {client_id: '1067161273424-gud6khml7r3bssi35u2rj5lchepj25bo.apps.googleusercontent.com'}
            ).then(function () {
                console.log("gapi done");
            })

            gauth.then(function () {
                console.log("google auth success");
                checkLoginStatus();

            }, function () {
                console.log("google auth faill");
            })
        });
    }
</script>

<script>
  // You can also require other files to run in this process
  require('./renderer.js')
</script>

<span id="name"></span>
<input type="button" id="loginBtn" value="checking.." onclick="
if(this.value==='Login'){
gauth.signIn().then(function() {
     console.log('gauth.signIn()');
checkLoginStatus();
});
}
else {
gauth.signOut().then(function() {
   console.log('gauth.signOut()');
checkLoginStatus();
});
}
">
    <script src="https://apis.google.com/js/platform.js?onload=init" async defer></script>

0 个答案:

没有答案