架构:Titanium Desktop 与 Twitter Streaming API

发布于 2024-12-23 16:00:29 字数 1048 浏览 1 评论 0原文

我是 Titanium 的新手,一开始尝试构建一个(又一个)Twitter 客户端。我遇到的问题是我想使用 Twitter 的 Streaming API,并且我我正在努力了解在 Titanium Desktop 中执行此操作的最佳方法。

以下是我看到的选项:

  1. 不要使用 Streaming API,它不会起作用。
  2. 构建一个与 支持流式响应的 httpclient 连接的 Python 桥< /a> (Streaming API 必需的,它永远不会关闭连接)。让该客户端将响应传递给 Javascript 方法,该方法会在推文出现时对其进行格式化和输出。 (这里的问题:如何捆绑我需要的 python 库?)
  3. 以某种我不知道的巧妙方式使用 Titanium SDK 1.1 附带的 Javascript HttpClient。
  4. 使用 Titanium SDK 的 1.2.0-RC2 版本,该版本附带支持 HttpClient用于流式响应。发行说明中几乎没有信息来判断流支持是否足以使 Streaming API 正常工作。
  5. 使用 twstreamer,这是一个通过 Flash 中介提供流支持的 JavaScript 库。我看到过错误报告指出 Flash 在 Titanium Desktop 中无法正常工作,但我希望被证明是错误的。
  6. 另一种方式我还没有想到。

我希望能得到关于如何让这项工作发挥作用的各种聪明的想法,以及未来的建议。感谢您的阅读!

I'm new to Titanium, and have started out by trying to build a (yet another) Twitter client. The problem I've encountered is that I would like to use Twitter's Streaming API, and I'm struggling to understand the best way to do that within Titanium Desktop.

Here's the options I see:

  1. Don't use the Streaming API, it's not going to work.
  2. Build a Python bridge that connects with a httpclient that supports streaming responses (required for the Streaming API, it never closes the connection). Let that client deliver the responses to a Javascript method that formats and outputs tweets as they come. (Problem here: How do I bundle the python libraries I need?)
  3. Use the Javascript HttpClient shipped with Titanium SDK 1.1 in some clever way I'm not aware of.
  4. Use the 1.2.0-RC2 release of Titanium SDK that ships with a HttpClient that has support for streaming responses. There's very little information in the Release notes to judge if the streaming support is enough to get things working with the Streaming API.
  5. Use twstreamer, a javascript library for streaming support through a Flash intermediary. I've seen bug reports stating the Flash does not work well inside Titanium Desktop, but I'd love to be proven wrong.
  6. Another way that I'm not yet thought of.

I'm hoping for all sorts of clever ideas of how I can get this working, and tips going forward. Thanks for reading!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

永不分离 2024-12-30 16:00:29

我对 Titanium 一点也不熟悉,但是浏览他们的文档,您最好的选择可能是使用 Titanium.Process 来分叉一些可以处理流响应的东西。这里有很多轻量级选项,但请注意,如果您想使用用户流,则需要一个支持 OAuth 和 SSL 的选项

I'm not at all familiar with Titanium, but looking through their docs your best bet is likely going to be to use Titanium.Process to fork something that can deal with streaming responses. There are plenty of lightweight options here, but note that if you want to use userstreams you'll need an option that supports OAuth and SSL

半城柳色半声笛 2024-12-30 16:00:29

以下是如何做到这一点(经过大量测试):

var xhr = Titanium.Network.createHTTPClient();
xhr.open("GET", "https://stream.twitter.com/1/statuses/filter.json?track=<Your-keyword-to-track>", true, '<Your-twitter-nickname>', '<Your-twitter-password>');
xhr.send();

var last_index = 0;
function parse() {
    var curr_index = xhr.responseText.length;
    if (last_index == curr_index) return; // No new data
    var s = xhr.responseText.substring(last_index, curr_index);
    last_index = curr_index;
    console.log(s);
}

var interval = setInterval(parse, 5000);
setTimeout(function(){
    clearInterval(interval);
    parse();
    xhr.abort();
}, 25000);

Here's how to do it (after LOTS of testing):

var xhr = Titanium.Network.createHTTPClient();
xhr.open("GET", "https://stream.twitter.com/1/statuses/filter.json?track=<Your-keyword-to-track>", true, '<Your-twitter-nickname>', '<Your-twitter-password>');
xhr.send();

var last_index = 0;
function parse() {
    var curr_index = xhr.responseText.length;
    if (last_index == curr_index) return; // No new data
    var s = xhr.responseText.substring(last_index, curr_index);
    last_index = curr_index;
    console.log(s);
}

var interval = setInterval(parse, 5000);
setTimeout(function(){
    clearInterval(interval);
    parse();
    xhr.abort();
}, 25000);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文