-1

I have the following code, which displays tweets in JSON format to an HTML page. I would like to display these tweets in a more presentable manner. Could anyone provide me with any options?

session_start();
require_once("twitteroauth-master/twitteroauth/twitteroauth.php"); //Path to twitteroauth library

$twitteruser = "massa_jes";
$notweets = 1;

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_encode($tweets); //decodes the json string to an array
var_dump($resArr);
Bud Damyanov
  • 30,171
  • 6
  • 44
  • 52
user2675041
  • 115
  • 1
  • 5
  • 15
  • You should be more specific as to what you're trying to achieve. Are you planning to embed the tweets in an HTML page? (Also, please remove the leading spaces from your code example.) – Nico Schlömer May 03 '15 at 10:39
  • Yes, I want the tweets to be embedded in an HTML page, and I have removed the leading spaces in my question – user2675041 May 03 '15 at 10:44
  • Well, if you want HTML then I suggest you pump out HTML instead of `var_dump($resArr);`. :) – Nico Schlömer May 03 '15 at 10:49

1 Answers1

0

Try the following

$tweetsArr = json_decode($tweets,true); //decodes the json string to an array
foreach($tweetsArr as $tweet) {
echo $tweet['text']."<br />";
...
...
}
  • This is what I was trying to go for, however I am being given the following error: Invalid argument supplied for foreach() – user2675041 May 03 '15 at 12:07
  • check the count of $tweetsArr if count($tweetsArr)=1 then try this foreach($tweetsArr[0] as $tweet) { –  May 05 '15 at 10:36