SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    815
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Twitter API -- problem grabbing the feed variable.......


    this is a follow-up to this thread..
    http://www.sitepoint.com/forums/show...arified-please


    Code:
    $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

    Code:
    var_dump($tweets);
    this does not print at all..
    Code:
    echo "bbbbb<p>" . $twitter . "</p>";

    so how do I embed this variable in HTML?

    this is also not printing....
    Code:
    $('#console').html(<?=$tweets?>);
    I don't get what's up with this...


    thank you...



  2. #2
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,389
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    When you make a call to the API like this:
    PHP Code:
    $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:
    PHP Code:
    $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.

  3. #3
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    815
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    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:

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

    thank you......

  4. #4
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,389
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by maya90 View Post

    and I get this error....




    line 52 is this line:

    Code:
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •