Google App Engine频道令牌无效

时间:2013-08-07 21:51:19

标签: javascript google-app-engine channel

我正在尝试通过将令牌复制并粘贴到输入框中来打开频道,但是控制台会返回,

  

无效+令牌。

以下是localhost:8080 /

的代码
<html>
  <head>
    <script type="text/javascript" src="https://talkgadget.google.com/talkgadget/channel.js"></script>
    <script>
      function OpenChannel(){
        channel = new goog.appengine.Channel(document.getElementById('Token').value);
        socket = channel.open();
        socket.onmessage = function(message){
          console.log(message);
        }
        socket.onopen = function(){
          connected = true;
          console.log('opened');
        }
        socket.onerror = function(err){
          console.log(err.description);
        }
        socket.onclose = function(){
          console.log('closed');
        }
      }
    </script>
  </head>
    <body>
      Token: <input id="Token"></input><br/>
      <button onclick="OpenChannel()">Open Channel</button>
    </body>
</html>

我正在通过打开“localhost:8080 / token?name = ...”创建令牌,它将通道令牌写入页面。这是该页面的python类:

class TokenPage(webapp2.RequestHandler):
  def get(self):
    token = channel.create_channel(self.request.get('name'))
    self.response.write(token)

我几乎已经复制了行的文档行,所以我不知道什么是错的。

解决方案:

替换

<script type="text/javascript" src="https://talkgadget.google.com/talkgadget/channel.js"></script>

<script type="text/javascript" src="/_ah/channel/jsapi"></script>

1 个答案:

答案 0 :(得分:1)

你试过了吗?

channel = new goog.appengine.Channel(document.getElementById('Token').value);