0

I have got all my tweet feed displaying... but it is completly out of format. COuld anyone point me in the right direction for the finishing touches? I have created a tweet model, with the results printing in the controller. But at the minute it is printing everything in the json file.. below is my model code...

<?php

class Tweet_model extends CI_Model {

public function __construct()
{
    $this->load->database();
}

public function get_tweet()
{
    // Load the rest client spark
    $this->load->spark('restclient/2.1.0');
    // Load the library
    $this->load->library('rest');
    // Run some setup
    $this->rest->initialize(array('server' => 'http://api.twitter.com/'));
    // Pull in an array of tweets
    $tweets = $this->rest->get('1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=jenksuy&count=2');
    return $tweets;
}

}

and below is my controller code...

 $myTweets = $this->tweet_model->get_tweet();

    print_r($myTweets);

but its displays every last bit of information in the json file like the following link...

https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=jenksuy&count=2

how could i fix this to just show the formatted tweets?

Chris Jenks
  • 33
  • 1
  • 6

1 Answers1

0

First of all, you parse the json data like this

$tweetobjects = json_decode($tweets)

Now if you want to display each message, you'll have to do something like this:

foreach ($tweetobjects['results'] as $tweet) {
echo $tweet['text'];
}
Crowlix
  • 1,269
  • 9
  • 19
  • I have added you code in now, however I am getting this error... 'json_decode() expects parameter 1 to be string, array given' – Chris Jenks May 07 '13 at 14:04
  • Try using this link instead: https://api.twitter.com/1/statuses/user_timeline.json?screen_name=jenksuy&count=2 – Crowlix May 08 '13 at 07:07