经过对Gnip的几次研究后,我将它集成到我的应用程序中,我设法添加新规则并从Gnip获取流结果,但现在我将它转换为PHP数组并显示它有问题
我使用了CURLOPT_RETURNTRANSFER =>是的,为了不打印卷曲结果,我将它存储到变量并使用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"}}}
答案 0 :(得分:0)
$content
print_r($arr)
),检查结构并根据它进行打印。答案 1 :(得分:0)
您似乎在rsult字符串 displayName 中有非UTF字符
您应该只将UTF字符用于JSON编码/解码功能。