dsj2014 2012-04-26 16:59
浏览 52

使用cURL输出

I'm planning to record the live tweets on a particular topic. For the same, I'm using the twitter stream API with cURL in PHP.

Here is the code:

<?php

$username = "xxxxx";
$password = "xxxxx";


$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://stream.twitter.com/1/statuses/filter.json?         track=SEARCH_PARAMETER');
curl_setopt($ch, CURLOPT_USERPWD, $username.":".$password);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$result = curl_exec($ch);
$jsonOBJ = json_decode ($result);

curl_close($ch);

print_r($jsonOBJ);
?>

My problem is, if I set CURLOPT_RETURNTRANSFER to 0, I can see the tweets on the terminal. But I'm not able to store in the variable $jsonOBJ and print it.

Please Help!

  • 写回答

4条回答 默认 最新

  • doudun2565 2012-04-26 17:10
    关注

    I'm working on the same kind of thing as well :) The problem is that when you do it in terminal, it's a stream, so the connection stays alive until you kill it. (ie the curl_exec() doesn't finish)

    Try looking at CURLOPT_PROGRESSFUNCTION and CURLOPT_READFUNCTION. They might give you some hints.

    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug