1
votes

I am trying to print the first tweet in the user timeline.

$hometimeline = $twitterObj->get_statusesHome_timeline();
$stream=$hometimeline->responseText;
$user=$stream[0]->user;
$tweet=$user->text;
echo $tweet;

This just won't print anything. What am I doing wrong here?

If I echo $hometimeline->responseText it shows on the screen
[
{"in_reply_to_status_id_str":null, "coordinates":null, "geo":null, "user":{"profile_use_background_image":true,"text":"I am back",....},"id_str":"121212"},

{ ... so on} ]

2

2 Answers

2
votes

you are getting a json string as response. Use json_decode to parse the response and you will be able to manage it as array o stdobject

do this just before interact with the response

$stream = json_decode( $hometimeline->responseText, true);

Edit

remember you can always use print_r to debug

0
votes

Try this instead:

$hometimeline = $twitterObj->get_statusesHome_timeline();
$stream = json_decode( $hometimeline->responseText );
$user=$stream[0]->user;
$tweet=$user->text;
echo $tweet;

json_decode turns the JSON string that you are receiving into a PHP object.