View
 

Html Twitter Badge to Display With Friends Timeline

Page history last edited by PBworks 16 years, 6 months ago

Here's a sample xhtml/javascript that uses the with_friends feed.

 

This is a modification of the XHTML/Javascript Twitter Badge that's available at http://twitter.com/badges

 

You must change the text "YOURUSERNAME" to your actual Twitter userID for this to work. And you must change it in 2 places.

 

You can also change the number of Twitter updates that are retrieved and displayed by changing the number "3" in the section of the script that reads: "twitterCallback&count=3" to a different number. The default is the last 3 Twitter updates.

 

Relative time script courtesy of Jon Aquino.

 


 


<div id="twitter_div">
<ul id="twitter_update_list"></ul></div>
<script src="http://twitter.com/javascripts/blogger.js" type="text/javascript"></script>
<ul id="twitter_list">


<script type="text/javascript">
  function relative_time(time_value) {

     var parsed_date = Date.parse(time_value);

     var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
     var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);

     if(delta < 60) {
         return 'less than a minute ago';
     } else if(delta < 120) {
         return 'about a minute ago';
     } else if(delta < (45*60)) {
         return (parseInt(delta / 60)).toString() + ' minutes ago';
     } else if(delta < (90*60)) {
         return 'about an hour ago';
     } else if(delta < (24*60*60)) {
         return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
     } else if(delta < (48*60*60)) {
         return '1 day ago';
     } else {
         return (parseInt(delta / 86400)).toString() + ' days ago';
     }
  }


function twitterCallback(obj) {
  var html = '';
  for (var i = 0; i < 3; i++) {
    html += '<li>' + obj[i].user.screen_name + ': ' + obj[i].text + '<br>' + '<span style="font-style:italic;">' + relative_time(obj[i].created_at) + '</span>' + '</li>';
}
  document.getElementById('twitter_list').innerHTML = html;
}
</script>


<script src="http://www.twitter.com/statuses/friends_timeline/YOURUSERNAME.json?callback=twitterCallback&count=3" type="text/javascript"></script>

<a style="font-size: 10px; text-decoration: none" href="http://twitter.com/YOURUSERNAME"><img border="0" src="http://static.twitter.com/images/twitter_bubble_logo.gif"/></a></ul>


You can replace the twitterCallback function above with:


function twitterCallback(obj) {
  var html = '';
  
  for (var i = 0; i < 3; i++) 
  {
    
	rExp = /((http|https|ftp)://(([A-Z0-9][A-Z0-9_-]*)(.[A-Z0-9][A-Z0-9_-]*)+)(/*)(:(d+))?([A-Z0-9_/.?~-]*))/gi
    text = new String(obj[i].text);
  	text = text.replace(rExp,'<a href="/$1">$1</a>');
  	rExp = /((@([A-Z0-9_]+)) )/gi
  	text = text.replace(rExp,'<a href="http://twitter.com/$3">$2</a> ');
    html += '<li><a href="http://twitter.com/' + obj[i].user.screen_name +'">' + obj[i].user.screen_name + '</a>: '; 
    html += text + '<br>' + '<span style="font-style:italic;">' + relative_time(obj[i].created_at) + '</span>' + '</li>';
  }
  document.getElementById('twitter_list').innerHTML = html;
}

 

This will hyperlink sender, @{name] and other URIs in the message.

 

Short code:


<script src="http://twitter.com/javascripts/blogger.js" type="text/javascript"></script>
<ul id="twitter_list"></ul>
<a style="font-size: 10px; text-decoration: none" href="http://twitter.com/YOURUSERNAME"><img border="0" src="http://static.twitter.com/images/twitter_bubble_logo.gif"/></a>
<script src="http://www.emailcommunications.nl/twitterit.js" type="text/javascript"></script>
<script src="http://www.twitter.com/statuses/friends_timeline/YOURUSERNAME.json?callback=twitterCallback&count=3" type="text/javascript"></script>

Comments (2)

emipac said

at 6:04 am on Jan 31, 2009

Hello, unfortunatelly im not a javascript expert, so i would like to ask how is that possible to predefine a username and password in the javascript source. I would like to remove the ask for authorization from the script. It would be nice if someone could help me:)

oyun said

at 4:21 am on May 31, 2010

http://www.kucukpatisserie.com/
http://www.gunalsen.com
http://www.kelebekcafe.net
http://www.mirclider.com
http://www.mirclider.net
http://www.mirclider.org
http://www.doruknet.org
http://www.dorukchat.net
http://www.dorukchat.org
http://www.netzurna.com
http://www.onursan.org
http://www.gevezechat.org
http://www.izmirchat.org
http://www.cinselchat.org
http://www.hanimeligelinlik.com
http://www.hanimeligelinlik.net
http://www.hanimeligelinlik.org
http://www.oyunlider.com
http://sikisyeri.blogspot.com/
http://fikra34.blogspot.com/
http://gunluk-filim.blogspot.com/
http://cinsel-muhabbet.blogspot.com
http://escinselsohbet.blogspot.com
http://cinselsohbetiniz.blogspot.com
http://gaysohbetiniz.blogspot.com
http://lezsohbetiniz.blogspot.com
http://ist-lgbtt.blogspot.com/
http://travesti34.blogspot.com/
http://gay34.blogspot.com/
http://gay-lez.blogspot.com/
http://gay-europa.blogspot.com/
http://drkcht.blogspot.com/
http://sarki-s0zleri.blogspot.com/
http://www.facebook.com/OnurSan.Fan
http://www.facebook.com/GunalSen
http://www.facebook.com/Partneriniz
http://www.facebook.com/AdultChat
http://twitter.com/OnurSanFan
http://twitter.com/DiningServices
http://twitter.com/WSUCougarscom
http://twitter.com/WSUCVMrecruit
http://cinselsohbet.blog.com/
http://gaychat.blog.com/
http://gaysohbet.blog.com/
http://sicaksohbet.blog.com/
http://sicakchat.blog.com/
http://sexchat.blog.com/
http://sexsohbet.blog.com/
http://diziizley1n.blog.com/
http://diziizleyin1.blog.com/
http://fikrabul.blog.com/
http://sikisturk.blog.com/
http://amcik.blog.com/
http://travesti.blog.com/
http://mircindir.blog.com/
http://mircyukle.blog.com/
http://kelebekindir.blog.com/
http://kelebekchat.blog.com/
http://kelebeksohbett.blog.com/
http://kelebektr.blog.com/
http://kelebekturk.blog.com/
http://trsohbet.blog.com/
http://chatnet.blog.com/
http://dalnet.blog.com
http://twitterfan.blog.com
http://oyun.pbworks.com

You don't have permission to comment on this page.