从twitter API json数据打印关联数组

时间:2015-12-09 22:17:40

标签: php arrays json twitter

当我尝试打印关联数组时,它在日志文件中给出了一个错误 PHP警告:在第28行的/var/www/html/twitter.php中为foreach()提供的参数无效

<?php
require_once('TwitterAPIExchange.php');
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "********",
'oauth_access_token_secret' => "********",
'consumer_key' => "**********",
'consumer_secret' => "************"
);
$url = 'https://api.twitter.com/1.1/search/tweets.json';
$requestMethod = 'GET';
$getfield = '?q=#naran';
$twitter = new TwitterAPIExchange($settings);
$string = json_decode($twitter->setGetfield($getfield)
            ->buildOauth($url, $requestMethod)
            ->performRequest(),true);

//if($string["errors"][0]["message"] != "") {echo "<h3>Sorry, there was a problem.</h3><p>Twitter returned the following error message:</p><p><em>".$string[errors][0]["message"]."</em></p>";exit();}

foreach($string as $items)
{
   echo "Time and Date of Tweet: ".$items['created_at']."<br />";
  echo "Tweet: ". $items['text']."<br />";



}
?>

0 个答案:

没有答案