0

in according to this tutorial:

$twitteruser = "twitterusername";
$notweets = 3;
$consumerkey = "12345";
$consumersecret = "123456789";
$accesstoken = "123456789";
$accesstokensecret = "12345";

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);

echo json_encode($tweets);
?>

How can I extract from json_encode($tweets); 'statuses' information?

simo
  • 79
  • 1
  • 4
  • 14

1 Answers1

2

Why are you using json_encode() here?

The response from Twitter is a JSON string, and you should use json_decode() to decode it into an an object/array and print the required values.

$tweetArray = json_decode($tweets, TRUE); // or json_decode($tweets); for an object

foreach($tweetArray as $value) {
    // do the printing ...
}
Amal Murali
  • 75,622
  • 18
  • 128
  • 150
  • Thank you for your replay, I've tried to use `json_decode()` but it gives me `"json_decode() expects parameter 1 to be string, array given"`. I've followed this tutorial: [link](http://stackoverflow.com/questions/17049821/setting-up-twitter-api-getting-the-last-few-tweets) – simo Sep 06 '13 at 15:10
  • @simo: As the error says, `json_decode` needs a JSON string. What library are you using? – Amal Murali Sep 06 '13 at 15:15
  • I've solved using this library: [twitter-api-php-master](https://github.com/J7mbo/twitter-api-php) – simo Sep 06 '13 at 15:50