我的网络应用程序要求用户通过twitter投票,并将这些选票显示在一个线条图上。我想用JavaScript来完成这整件事。
我的要求:
发布于 2011-06-20 22:10:23
使用twitter,我需要实时收集选票,并将这些选票显示在一行图表中,实时显示!
如果你在做实时的事情,你想要使用流API。使用现有的开源客户端实现(如平喉 )来快速启动和运行是相当容易的。它也有一些很好的例子。
这里就是他们追踪大量关键词的例子:你可能会想要追踪人们正在投票的任何标签:
<?php
require_once('../lib/Phirehose.php');
/**
* Example of using Phirehose to display a live filtered stream using track words
*/
class FilterTrackConsumer extends Phirehose
{
/**
* Enqueue each status
*
* @param string $status
*/
public function enqueueStatus($status)
{
/*
* In this simple example, we will just display to STDOUT rather than enqueue.
* NOTE: You should NOT be processing tweets at this point in a real application, instead they should be being
* enqueued and processed asyncronously from the collection process.
*/
$data = json_decode($status, true);
if (is_array($data) && isset($data['user']['screen_name'])) {
print $data['user']['screen_name'] . ': ' . urldecode($data['text']) . "\n";
}
}
}
// Start streaming
$sc = new FilterTrackConsumer('username', 'password', Phirehose::METHOD_FILTER);
$sc->setTrack(array('morning', 'goodnight', 'hello', 'the'));
$sc->consume();如果你的音量很低,你可以直接把推特推到enqueueStatus的数据库里。
发布于 2011-06-20 20:52:23
你检查过Twitter-API本身了吗?
http://dev.twitter.com/doc
文档非常冗长,还包含了一些关于如何在JavaScript中使用它的示例。(我不确定,您可能需要唱歌或注册才能访问api )。
https://stackoverflow.com/questions/6417005
复制相似问题