Simple page





Wednesday, 12 June 2013 14:03

How to Display Twitter Posts with the new 1.1 Api - jQuery script

Many of you might have not heard about the lattest Twitter api changes but not all of you got ready on time right?

We will see how to create an easy plugin in order to draw lattest Twiteer posts from an account.


First of all, due to the lattest changes indroduced from Twitter team OAuth is required in order to validate the user or script, more info here:

You can find the hole procedure here:


In a few worlds you need to create a Twitter application on the page:

With your Unique namespace and custom options and once you have your Access Tokens you are good to go!


Now all we need in order to get the latest Tweets from our page is use the function GET Statuses / usertimeline

So we create our custom javascript function named getTweets witch uses in this case jQuery library and codebird framework

$.fn.getTweets = function(options) {
 var defaults = {
 tweets: 5,
 before: '',
 after: '',
 key: '',
 keysec: '',
 token: '',
 tokensec: ''
var options = $.extend(defaults, options);

 var cb = new Codebird;
 cb.setConsumerKey(options.key, options.keysec);

 cb.setToken(options.token, options.tokensec);

 return this.each(function() {
 var obj = $(this);

 {count: options.tweets},
  function (reply) {
    $.each(reply, function(i, tweet) {
    if(tweet.text !== undefined) {

    var tweethref= tweet.text.split(" ",1);
<a class="external" href="/+tweethref+">'+tweet.text+'</a>'+options.after);


After having this hole function, all we have to do is execute a jquery script on page load placing it where we please.

<script type="text/javascript">// ![DATA[
// ![DATA[
$(document).ready(function() { $('#getTweets').getTweets({ tweets: 5,
				key: 'BaqRhGUU7BwlPjO1sQ5H8w',
				keysec: 'tnrLnA53W1cESxkvlr9vkIWqXXXXXXXXXX,
				token: '
				519748211 - DMhkgVPgVKPYq3tYjUVP5Pd6E1OaVth5n2zBZ6Hi ',
				tokensec: '

// ]]></script>

You can find the hole script attached, enjoy!

Read 6776 times Last modified on Monday, 29 July 2013 17:29

Leave a comment