Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP从json获取twitter实体值_Php_Json_Twitter - Fatal编程技术网

使用PHP从json获取twitter实体值

使用PHP从json获取twitter实体值,php,json,twitter,Php,Json,Twitter,我在twitter的json提要中循环浏览每一条tweet。代码的第一部分工作完美 $screen_name = "BandQ"; $count = 10; $urlone = json_decode(file_get_contents("http://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=false&screen_name=BandQ&count

我在twitter的json提要中循环浏览每一条tweet。代码的第一部分工作完美

$screen_name = "BandQ";
$count = 10;


$urlone = json_decode(file_get_contents("http://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=false&screen_name=BandQ&count=".$count."&page=1"),true);
$urltwo = json_decode(file_get_contents("http://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=false&screen_name=BandQ&count=".$count."&page=2"),true);

$data = array_merge_recursive( $urlone, $urltwo);


// Output tweets
//$json = file_get_contents("http://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=false&screen_name=".$screen_name."&count=".$count."", true);
//$decode = json_decode($json, true);

$count = count($data); //counting the number of status

$arr = array();
for($i=0;$i<$count;$i++){
    $text = $data[$i]["text"]." ";
     $retweets = $data[$i]["text"]."<br>Retweet Count: ".$data[$i]["retweet_count"]. "<br>Favourited Count: ".$data[$i]["favorite_count"]."<br>".$data[$i]["entities"]["user_mentions"][0]["screen_name"]."<br>";
    // $arr[] = $text;
    $arr[] = $retweets;
}

// Convert array to string
$arr = implode(" ",$arr);
print_r($arr);
如何获取屏幕名称值


非常感谢

告诉我们您正在使用的代码不起作用上面的一行不是引发此错误的代码,请告诉我们第29行与您所写的完全一致,第29行是以$retweets开头的一行。我只是没有正确地遍历json。多次尝试均无效。正在到达,但现在收到通知:第30行C:\xampp\htdocs\tweets.php中的未定义偏移量:0
Notice: Array to string conversion in C:\xampp\htdocs\tweets.php on line 29

Notice: Use of undefined constant user_mentions - assumed 'user_mentions' in C:\xampp\htdocs\tweets.php on line 29

Notice: Use of undefined constant screen_name - assumed 'screen_name' in C:\xampp\htdocs\tweets.php on line 29