I have the following code, in which I am getting Tweets in JSON format on an HTML page, I want this to be displayed neatly on an HTML page. I have included the foreach loop, however I am getting the following error: " json_decode() expects parameter 1 to be string, array given ".
function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret)
{
$connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
return $connection;
}
$connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
$tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitteruser."&count=".$notweets);
$resArr = json_decode($tweets, 1); // decodes the json string to an array
if (is_array($resArr))
{
foreach ($resArr as $tweet)
{
echo $tweet['text']."<br />";
}
}
I have also tried using the following code, after reading other suggestions, however an error "Using $this when not in object context":
$resArr = json_decode($this->item->extra_fields, true);
Would anyone please provide me with some guidance?