doucan8521 2012-03-16 21:01
浏览 43
已采纳

如何在我的数据库中存储带有特定主题标签的推文? [关闭]

I want to monitor and store all tweets with a hashtag '#myDDD' into my MySQL database. I want to store the username of the guy who tweeted, the content of the tweet and the timestamp. I have a table with 'username', 'tweet' and 'time'. Ideally I wouldn't want to get retweets.

  • 写回答

1条回答 默认 最新

  • dongqi6964 2012-03-17 10:27
    关注

    Use this

    <?php
    function load_tweets($url) {
        $ch = curl_init();
        curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5);
        return json_decode(curl_exec($ch));
        curl_close($ch);
    }
    $TwitterData = load_tweets("http://search.twitter.com/search.json?q=%23myDDD");
    $DataYouWant = array();
    foreach($TwitterData->results as  $value) {
            $DataYouWant[] = array( "tweet" => $value->text,
                                    "username" => $value->from_user_name,
                                    "time" => $value->created_at);
    }
    ?>
    

    You have the data you wanted in the $DataYouWant array, but you will probably insert the data to your databas inside the foreach block and get rid of the $DataYouWant array. BTW there is no tweets with the hashtag #myDDD so change it, otherwise you will not get anything back.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里