Twitter API -- problem grabbing the feed variable

[FONT=Verdana]
this is a follow-up to this thread…

$tweets = $twitter->get('statuses/user_timeline.json?screen_name=NewYorker&count=6');  

I don’t get why the only way to grab this $tweets var is

var_dump($tweets); 

this does not print at all…

echo "bbbbb<p>" . $twitter . "</p>";

so how do I embed this variable in HTML?

this is also not printing…

$('#console').html(<?=$tweets?>);

I don’t get what’s up with this…

thank you…

[/FONT]

When you make a call to the API like this:

$tweets = $twitter->get('statuses/user_timeline.json?screen_name=NewYorker&count=6');

what you’re getting back is a collection of tweets, either as raw JSON or decoded as a PHP array of StdClass objects. In the case of the latter, you can’t just output it as if it were a string, you have to iterate over the array and do something with the data for each tweet.

Here’s an example:


$tweets = $twitter->get('statuses/user_timeline.json?screen_name=NewYorker&count=6');

echo '<ul>';
foreach ($tweets as $tweet) {
    echo "<li>{$tweet->text}</li>";
}
echo '</ul>';

The API just returns the data in a structured format, it doesn’t contain any HTML. You’re responsible for the presentation of the data.


and I get this error…

Catchable fatal error: Object of class TwitterOAuth could not be converted to string in /Library/WebServer/Documents/_tw/tweets.php on line 52

line 52 is this line:

echo "bbbbb<p> $twitter </p>";


thank you…

Sure, $twitter is the TwitterOAuth object… if you try and echo it, it’s going to give you that error because it’s an object not a string.