2

First of all I'm using the code mentioned here. I did everything as someone suggested, I generated keys to my app and put it in the code. When I ran it, I saw the huge json string with basically everything over there. Here's a part of it to show you exactly what I'm getting:

Array ( [0] => stdClass Object ( [created_at] => Thu May 14 20:06:37 +0000 2015 [id] => 5989425114966784000 [id_str] => 5989425114966784000 [text] => This is my first tweet #hello [source] => Twitter Web Client [truncated] => [in_reply_to_status_id] => [in_reply_to_status_id_str] => [in_reply_to_user_id] => [in_reply_to_user_id_str] => [in_reply_to_screen_name] => [user] => stdClass Object ( [id] => 3064494912 [id_str] => 3064494912 [name] => hellomotoUserName [screen_name] => helloHQ [location] => [description] => [url] => [entities] => stdClass Object ( [description] => stdClass Object ( [urls] => Array ( ) ) ) [protected] => [followers_count] => 0 [friends_count] => 0 [listed_count] => 0 [created_at] => Fri Feb 27 17:39:51 +0000 2015 [favourites_count] => 0 [utc_offset] => 7200 [time_zone] => Belgrade [geo_enabled] => [verified] => [statuses_count] => 3 [lang] => en [contributors_enabled] => [is_translator] => [is_translation_enabled] => [profile_background_color] => C0DEED [profile_background_image_url] => http://abs.twimg.com/images/themes/theme1/bg.png [profile_background_image_url_https] => https://abs.twimg.com/images/themes/theme1/bg.png [profile_background_tile] => [profile_image_url] => http://pbs.twimg.com/profile_images/5975166356332425/fXmL-aI__normal.png [profile_image_url_https] => https://pbs.twimg.com/profile_images/5975166356332425/fXmL-aI__normal.png [profile_link_color] => 0084B4 [profile_sidebar_border_color] => C0DEED [profile_sidebar_fill_color] => DDEEF6 [profile_text_color] => 333333 [profile_use_background_image] => 1 [has_extended_profile] => [default_profile] => 1 [default_profile_image] => [following] => [follow_request_sent] => [notifications] => ) [geo] => [coordinates] => [place] => [contributors] => [is_quote_status] => [retweet_count] => 0 [favorite_count] => 0 [entities] => stdClass Object ( [hashtags] => Array ( [0] => stdClass Object ( [text] => hello [indices] => Array ( [0] => 35 1 => 43 ) ) 1 => stdClass Object ( [text] => hashtag [indices] => Array ( [0] => 45 1 => 53 ) ) ) [symbols] => Array ( ) [user_mentions] => Array ( ) [urls] => Array ( ) ) [favorited] => [retweeted] => [lang] => en ) 1 => stdClass Object ( [created_at] => Tue May 12 20:38:39 +0000 2015 [id] => 598225796945847936 [id_str] => 598225796945847936 [text] => This is my second tweet #hello [source] => Twitter Web Client [truncated] => [in_reply_to_status_id] => [in_reply_to_status_id_str] => [in_reply_to_user_id] => [in_reply_to_user_id_str] => ...

etc.

On the other hand - there's my webpage, on which I have this twitter container:

<section class="twitter-container">
            <div class="twitter">
                <ul class="tweet_list" id="tweet_list">
                    <li class="tweet_first tweet_even">
                        <span class="tweet_text">I want to put here the text from my latest tweets</span><span class="tweet_time"><a href="http://twitter.com/mytwitteraccount" title="view tweet on twitter">date of first tweet</a></span>
                    </li>
                    <li class="tweet_even">
                        <span class="tweet_text">Again, the same as above, how can I put here latest #tweet?
                            <a href="#">#myFirstTweet</a></span><span class="tweet_time"><a href="http://twitter.com/mytwitteraccount" title="view tweet on twitter">date of 2nd tweet</a></span>
                    </li>

                </ul>
            </div>
        </section>

And now - could you help me with parsing the json and fitting the results in my html code? I want to put there e.g. last 5 tweets with their date and time.. Thanks a lot

Community
  • 1
  • 1
randomuser1
  • 2,733
  • 6
  • 32
  • 68

1 Answers1

1

You can use this code ($tweets variable is the array with all the tweets):

<section class="twitter-container">
    <div class="twitter">
        <ul class="tweet_list" id="tweet_list">
            <?php $t = 0; ?>
            <?php foreach ($tweets as $tweet) { ?>
                <?php $t++; ?>
                <?php if ($t>5) break; ?>
                <li class="<?php if ($t==1) print 'tweet-first'; ?> tweet-<?php print $t; ?> tweet_even">
                    <span class="tweet_text"><?php print $tweet->text; ?></span><span class="tweet_time"><a href="http://twitter.com/mytwitteraccount" title="view tweet on twitter"><?php print $tweet->created_at; ?></a></span>
                </li>
            <?php } ?>
        </ul>
    </div>
</section>
Nomad Webcode
  • 816
  • 5
  • 9