消费的Twitter流API [英] Consuming twitter stream API

查看:155
本文介绍了消费的Twitter流API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要消耗实时鸣叫样本。我有这块code,但我无法得到任何马我调用正确的链接。肯定我把正确的用户名和密码,但仍然没有通过。请指点是不是因为最近的Twitter改变了API。很抱歉,如果问题是基本我是新来的。在此先感谢

 < PHP
//datacollector.php
$计划生育=
FOPEN(HTTP://用户名:pass@stream.twitter.com/spritzer.json
而($数据=与fgets($ FP))
{
    $ =时间日期(YmdH);
    如果($ NEWTIME!= $时间)
    {
        @fclose($ FP2);
        $ FP2 =的fopen({$}时间.TXT,A);
    }
    的fputs($ FP2,$数据);
    $ NEWTIME = $时间;
}
?>


解决方案

什么DWRoelands帖子是关于德precation真实的,但实际上不是你的问题 - 问题是,微博的德precated spritzer.json 。您应该改用 /1/statuses/sample.json 来得到流水。下面是工作的命令行示例:

 卷曲http://stream.twitter.com/1/statuses/sample.json -Uusername:密码

如果你打算使用这种code生产中很长一段时间,我肯定会考虑实施的OAuth,但由于微博甚至还没有宣布关闭基本认证的时间表,也没有抢,如果你'重新只是鬼混。当然,他们可以把它关掉,明天没有任何警告。

实际凭据密码:

下面是一些工作PHP code,只需更换用户名

 < PHP
//datacollector.php
$计划生育=的fopen(HTTP://用户名:password@stream.twitter.com/1/statuses/sample.json,R);
而($数据=与fgets($ FP)){
    $ =时间日期(YmdH);
    如果($ NEWTIME!= $时间){
        @fclose($ FP2);
        $ FP2 =的fopen({$}时间.TXT,A);
    }
    的fputs($ FP2,$数据);
    $ NEWTIME = $时间;
}
?>

I need to consume the real time tweets sample. I have this piece of code but i could not get anything ma i calling the right link. definitely i put the right username and password but still it did not go through. Please advice is it because twitter changed the API recently. Sorry if the question is basic I am new to that. Thanks in advance

<?php
//datacollector.php
$fp =
fopen("http://username:pass@stream.twitter.com/spritzer.json
while($data = fgets($fp))
{
    $time = date("YmdH");
    if ($newTime!=$time)
    {
        @fclose($fp2);
        $fp2 = fopen("{$time}.txt","a");
    }
    fputs($fp2,$data);
    $newTime = $time;
}
?>

解决方案

What DWRoelands posts is true about deprecation, but that's not actually your problem -- the problem is that Twitter deprecated spritzer.json. You should instead use /1/statuses/sample.json to get the firehose. Here's a command-line example that works:

curl http://stream.twitter.com/1/statuses/sample.json -uusername:password

If you're looking to use this code in production for a long time, I would certainly consider implementing OAuth, but since Twitter hasn't even announced a schedule for turning off Basic Auth, there's no rush if you're just fooling around. Of course, they could turn it off tomorrow without any warning.

Here's some working PHP code, just replace username:password with actual credentials:

<?php
//datacollector.php
$fp = fopen("http://username:password@stream.twitter.com/1/statuses/sample.json", "r");
while($data = fgets($fp)) {
    $time = date("YmdH");
    if ($newTime!=$time) {
        @fclose($fp2);
        $fp2 = fopen("{$time}.txt","a");
    }
    fputs($fp2,$data);
    $newTime = $time;
}
?>

这篇关于消费的Twitter流API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆