【问题标题】:Count tweets using a hashtag使用主题标签计算推文
【发布时间】:2011-07-08 17:59:39
【问题描述】:

我正在开发一个 Twitter 应用程序,但遇到了一个我无法解决的问题。请问你能帮帮我吗? 该应用程序用于品牌推广。我们需要使用标签计算每条推文,并给推文#50000 的作者一个价格。我们如何从 Twitter API 获取数据并识别推文 #50000?感谢您的帮助!

我们使用 PHP 和 MySQL。

【问题讨论】:

  • 请分享您到目前为止所做的尝试。

标签: php mysql api twitter


【解决方案1】:

我将首先查看phirehose,这将允许您获取推文。您还可以使用Ruby Twitter Gem,它有很好的文档记录,如果您对 ruby​​ 感到满意,它似乎很容易使用。

【讨论】:

  • 反对 Ruby 参考。 OP 明确声明他们使用 PHP 和 MySQL
【解决方案2】:

这个获取计数标签(#)twitter的php源代码

<?php
   global $total, $hashtag;
   //$hashtag = '#supportvisitbogor2011';
   $hashtag = '#australialovesjustin';
   $total = 0;
   function getTweets($hash_tag, $page) {
      global $total, $hashtag;
      $url = 'http://search.twitter.com/search.json?q='.urlencode($hash_tag).'&';
      $url .= 'page='.$page;    
      $ch = curl_init($url);
      curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
      $json = curl_exec ($ch);
      curl_close ($ch);
      //echo "<pre>";    
      //$json_decode = json_decode($json);
      //print_r($json_decode->results);

      $json_decode = json_decode($json);        
      $total += count($json_decode->results);    
      if($json_decode->next_page){
         $temp = explode("&",$json_decode->next_page);        
         $p = explode("=",$temp[0]);                
         getTweets($hashtag,$p[1]);
      }        
   }

   getTweets($hashtag,1);
   echo $total;
?>

谢谢..

【讨论】:

    【解决方案3】:

    我昨晚正在查这个。您可以请求 URL 即。 http://search.twitter.com/search.json?q=%23hashtag

    (这是文档页面http://dev.twitter.com/doc/get/search

    说一个 5 分钟的 cron 脚本,记录你获得的最后一条推文 ID,将其传递给搜索 URL since_id 参数,同时记录你计算过的推文数量,可选择将每条推文存储在供参考的表格...这是我的 2 美分

    【讨论】:

    • 它只会列出最近标记的帖子......他需要设置cron作业来监控这些推文,即使那样50000实际上不太可能是50000推文......
    • 流媒体 API 将更加准确,因为它会在编写推文时返回推文。搜索 API 会遍历旧推文,我认为这不是 @abotella 想要实现的目标。
    猜你喜欢
    • 2012-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-17
    • 2015-07-08
    • 1970-01-01
    • 2014-07-31
    • 2014-06-14
    相关资源
    最近更新 更多