0

在对 Gnip 进行了几次研究之后,我将它集成到了我的应用程序中,并且我设法添加了新规则并从 Gnip 获取流结果,但是现在我在将其转换为 PHP 数组并显示它时遇到了问题

我使用 CURLOPT_RETURNTRANSFER => TRUE 来不打印 curl 结果,并将其存储到变量中并使用 json_decode 函数对其进行解码,然后打印它但仍然得到一个空页面。

如果有人可以帮助我,这对我来说将节省大量时间

提前致谢

这是我的代码

 $ch = curl_init();
    curl_setopt_array($ch, array(
        CURLOPT_URL => $stream_url,
        CURLOPT_ENCODING => "gzip",
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
        CURLOPT_USERPWD => $user.":".$pass,
        CURLOPT_WRITEFUNCTION => "print_out_data",
       CURLOPT_RETURNTRANSFER => TRUE,
        CURLOPT_LOW_SPEED_TIME=> 60,
        CURLOPT_TIMEOUT => 10,

 //CURLOPT_VERBOSE => true // uncomment for curl verbosity

    ));


    $content = curl_exec($ch);

    $arr = json_decode($content, true);
    $foo = $arr['id']; 
    $bar = $arr['objectType']; 

   print_r($foo);
    print_r($bar);

打印时得到的结果

{"id":"tag:search.twitter.com,2005:304468052219662336","objectType":"activity","actor":{"objectType":"person","id":"id:twitter.com:348088144","link":"http://www.twitter.com/Devin_Giordan0","displayName":"ᎠƎϑᎥИ ᗩИ✞ℍ⚙ИУ","postedTime":"2011-08-03T21:21:01.000Z","image":"http://a0.twimg.com/profile_images/3271229767/481419170edf2c639441ce43cd540f0e_normal.jpeg","summary":"I will see a Million Before I diee\nInstagram-Youngnrecklessss\nFollow me and ill follow back \nFuck what people think, stay real. ","links":[{"href":null,"rel":"me"}],"friendsCount":476,"followersCount":265,"listedCount":0,"statusesCount":2773,"twitterTimeZone":null,"verified":false,"utcOffset":null,"preferredUsername":"Devin_Giordan0","languages":["en"],"location":{"objectType":"place","displayName":"Brooklyn, Ny"}},"verb":"share","postedTime":"2013-02-21T05:50:15.000Z","generator":{"displayName":"Echofon","link":"http://www.echofon.com/"},"provider":{"objectType":"service","displayName":"Twitter","link":"http://www.twitter.com"},"link":"http://twitter.com/Devin_Giordan0/statuses/304468052219662336","body":"RT @julianneromero1: All I wanna do is make youuu happy ","object":{"id":"tag:search.twitter.com,2005:304448192165076993","objectType":"activity","actor":{"objectType":"person","id":"id:twitter.com:383846395","link":"http://www.twitter.com/julianneromero1","displayName":"julieeeeee","postedTime":"2011-10-02T16:35:38.000Z","image":"http://a0.twimg.com/profile_images/3259175129/bdd9337b0e266c851a471f7034ca319a_normal.jpeg","summary":"Old enough to know better, young enough to not give a fuck. ✊","links":[{"href":null,"rel":"me"}],"friendsCount":409,"followersCount":483,"listedCount":0,"statusesCount":18986,"twitterTimeZone":"Quito","verified":false,"utcOffset":"-18000","preferredUsername":"julianneromero1","languages":["en"]},"verb":"post","postedTime":"2013-02-21T04:31:20.000Z","generator":{"displayName":"Twitter for iPhone","link":"http://twitter.com/download/iphone"},"provider":{"objectType":"service","displayName":"Twitter","link":"http://www.twitter.com"},"link":"http://twitter.com/julianneromero1/statuses/304448192165076993","body":"All I wanna do is make youuu happy ","object":{"objectType":"note","id":"object:search.twitter.com,2005:304448192165076993","summary":"All I wanna do is make youuu happy ","link":"http://twitter.com/julianneromero1/statuses/304448192165076993","postedTime":"2013-02-21T04:31:20.000Z"},"twitter_entities":{"hashtags":[],"urls":[],"user_mentions":[]}},"twitter_entities":{"hashtags":[],"urls":[],"user_mentions":[{"screen_name":"julianneromero1","name":"julieeeeee","id":383846395,"id_str":"383846395","indices":[3,19]}]},"retweetCount":5,"gnip":{"matching_rules":[{"value":"Happy","tag":null}],"klout_score":42,"language":{"value":"en"}}} {"id":"tag:search.twitter.com,2005:304468052492300288","objectType":"activity","actor":{"objectType":"person","id":"id:twitter.com:1192574623","link":"http://www.twitter.com/Krystlegtsi","displayName":"Tracee Pavlik","postedTime":"2013-02-18T09:14:11.000Z","image":"http://a0.twimg.com/profile_images/3271765828/92aae4995378723671641594159a6ad7_normal.jpeg","summary":null,"links":[{"href":"http://tinyurl.com/b23r4ee","rel":"me"}],"friendsCount":20,"followersCount":0,"listedCount":0,"statusesCount":4,"twitterTimeZone":null,"verified":false,"utcOffset":null,"preferredUsername":"Krystlegtsi","languages":["en"]},"verb":"post","postedTime":"2013-02-21T05:50:15.000Z","generator":{"displayName":"web","link":"http://twitter.com"},"provider":{"objectType":"service","displayName":"Twitter","link":"http://www.twitter.com"},"link":"http://twitter.com/Krystlegtsi/statuses/304468052492300288","body":"It was an Amazing event tonight ...and makes me happy to see the president is educated speaks English Mashallah.","object":{"objectType":"note","id":"object:search.twitter.com,2005:304468052492300288","summary":"It was an Amazing event tonight ...and makes me happy to see the president is educated speaks English Mashallah.","link":"http://twitter.com/Krystlegtsi/statuses/304468052492300288","postedTime":"2013-02-21T05:50:15.000Z"},"twitter_entities":{"hashtags":[],"urls":[],"user_mentions":[]},"retweetCount":0,"gnip":{"matching_rules":[{"value":"Happy","tag":null}],"language":{"value":"en"}}}
4

2 回答 2

0

看来您在 rsult 字符串的displayName中有非 UTF 字符

对于 JSON 编码/解码函数,您应该只使用 UTF 字符。

于 2013-02-21T08:10:58.073 回答
0
  1. 检查内容$content
  2. 如果内容在那里,则检查 ( print_r($arr)),检查结构并根据它打印。
于 2013-02-21T05:43:24.393 回答