繁体   English   中英

Twitter搜索API(2)

[英]Twitter Search API (2)

我的Web应用程序要求用户通过Twitter投票,并在折线图中显示这些投票。 我想使用JavaScript完成这件事。

我的要求:

  • 使用twitter API,我需要实时收集投票,​​并将这些投票实时显示在折线图中!

您是否检查过Twitter-API本身?

http://dev.twitter.com/doc

该文档非常冗长,并且还包含一些有关如何将其与JavaScript一起使用的示例。 (不确定,可能您必须唱歌或注册才能访问该api)。

使用twitter API,我需要实时收集投票,​​并将这些投票实时显示在折线图中!

如果您要进行实时操作,则想使用Streaming API 使用现有的开源客户端实现(例如Phirehose)可以快速启动并运行。 它还带有一些很好的例子。

是他们的示例,这些示例跟踪一堆关键字:您可能想跟踪人们在投票的任何主题标签:

<?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中的数据库。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM