我的web应用程序要求用户通过twitter投票并在折线图上显示这些投票。我喜欢用JavaScript来完成这件事。Twitter搜索API(2)
我的要求:
- 使用Twitter的API,我需要收集选票实时,有一个折线图中显示的那些票,实时!
我的web应用程序要求用户通过twitter投票并在折线图上显示这些投票。我喜欢用JavaScript来完成这件事。Twitter搜索API(2)
我的要求:
使用twitter API,我需要实时收集投票并将这些投票实时显示在折线图中!
如果你正在做实时的东西,你想使用Streaming API。使用现有的开源客户端实现(如Phirehose)来快速启动和运行相当容易。它也带有一些很好的例子。
Here的他们为榜样,跟踪一堆关键字:你可能会希望跟踪任何主题标签的人投票:
<?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中直接进入数据库。
您是否检查过Twitter-API本身?
该文档是非常冗长,还包含有关如何使用JavaScript使用它的一些例子。 (可能你必须唱歌或注册才能访问api,我不确定)。
我有......这是呃......谢谢! – Oakin
PaulV ...谢谢兄弟!好东西在这里! – Oakin
@Oakin:没问题。对于图表,我过去曾使用过Google的[可视化API](http://code.google.com/apis/chart/interactive/docs/gallery.html)。我建议检查一下,这很简单。 –
我会计划使用Google可视化AP ......我之前也使用它,它非常连续FWD!再次感谢您的帮助! – Oakin