【问题标题】:url for channel api appears to be empty ( GAE channel) works on dev, not on google频道 api 的网址似乎为空(GAE 频道)适用于开发人员,而不适用于谷歌
【发布时间】:2013-07-10 00:31:25
【问题描述】:

我有一个使用 GAE 频道 API 的简单完整应用程序。它可以在我的本地机器上运行,但是当我将它上传到 apppot 时,通道 api 应该是的 url 似乎是空的,并且应用程序失败并显示消息“goog is not found”。

服务器:

import webapp2
import jinja2
import os
import time
import logging

channel_key = 'key'

class MainHandler(webapp2.RequestHandler):
    def get(self):
    token = channel.create_channel("1")
        template_values = {'token': token}
        template = env.get_template('index.html')
        self.response.write(template.render(template_values))

class OpenedHandler(webapp2.RequestHandler):
    def post(self):
        channel.send_message("1", "hi") 
    logging.info("send hi");

env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__))) 
app = webapp2.WSGIApplication([
    ('/', MainHandler),
    ('/opened', OpenedHandler)
], debug=True)

客户:

<!DOCTYPE html>
<html>
<body>
<div id="debug">_</div>

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

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

function debug(s) {
    document.getElementById("debug").innerHTML = s;
}   
my_func = function() {
    var xhr = new XMLHttpRequest();
    xhr.open('POST', '/opened');
    xhr.send();
}           
onOpened = function() {
    debug("open");
    setTimeout(my_func, 2000);
};      

onMessage = function(message) {
    alert("something recieved");
    alert(message);
}       

channel = new goog.appengine.Channel("{{token}}")  // this is where it fails
socket = channel.open();
socket.onopen = onOpened;
socket.onmessage = onMessage;
socket.onerror = function(e){
    alert("error:"+e['description']);
};      
socket.onclose = function(){
    alert("close");
};      

</script>
</body>
</html>

在我的本地机器上,调用 onOpened 函数并发送消息。在 apppot 上安装时,我得到了

"Uncaught ReferenceError: goog is not defined" 

紧接着

channel = new goog.appengine.Channel("{{token}}")

当我查看开发工具窗口的资源选项卡并单击“jsapi”时,它似乎是空的:


(来源:crb at www.sonic.net

我尝试过其他的 url,你可以看到这些在 html 中被注释掉了,但是没有任何效果。我很确定这是正确的,我无法解释为什么 api 似乎是空的,因此没有定义“goog”。

感谢您的任何建议。

【问题讨论】:

  • Grrr。我刚刚注意到这在 Safari 上运行良好,谷歌今天或昨天自动将我的 Chrome 更新到了新版本。所以我认为这是 Chrome 的问题。
  • 尝试刷新缓存。
  • 感谢您的想法。我确实清除了缓存。结果相同。
  • 也可以在 Firefox 中使用。只是不是 Chrome。

标签: google-app-engine channel-api


【解决方案1】:

我有同样的问题。看看你是否在&lt;/body&gt; 应答器之前添加了以下代码。

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

这修复了我的“未找到 goog”错误。

【讨论】:

    【解决方案2】:

    对我来说,这是由 Chrome 的 Disconnect 插件引起的,它阻止了 /_ah/channel/jsapi 重定向到的 URL。唯一的解决方案是禁用该页面的断开连接。

    我将尝试告诉 Disconnect 开发人员不应阻止该 URL,因为它可能为加载它的任何页面提供重要功能。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-15
      • 2021-06-17
      • 2022-11-10
      • 1970-01-01
      • 1970-01-01
      • 2014-03-09
      • 2020-10-12
      • 1970-01-01
      相关资源
      最近更新 更多