Google App Engine channel token is invalid

半城伤御伤魂 提交于 2019-12-13 18:03:22

问题


I'm trying to open a channel by copying and pasting a token into an input box, however the console returns,

Invalid+token.

Here is the code for 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>

I'm creating the token by opening, "localhost:8080/token?name=...", which writes the channel token to the page. Here is the python class for that page:

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

I've pretty much copied the documentation line for line, so I have no idea whats going wrong.

Solution:

replace

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

with

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


回答1:


Have you tried:

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


来源:https://stackoverflow.com/questions/18114455/google-app-engine-channel-token-is-invalid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!