Friday, October 21, 2011
Add Twitter to your webpage , Display Tweets using Java script
Hi, Everyone like to display tweets on their webpage. Twitter api provides the way to do it..All you need to do is trigger a event in java script which retrives last 20 tweets. We can get tweets in two format xml and Json.. I prefer JSON which is very easy to use. I have used JSON. when page is loaed $.getJSON method is called and parameter is passed. i am parsing the return json data and appending it to the div element which shows all tweets.
But the problem is you can not refresh the page many times . i think 3 or 4 .. if u refresh more than 3 to 4 times. .Twitter server denies your request. You have to wait for some more time(Minimum 5 min. Not sure).. To avoid these kind of problem my solution would be to store values in cookies or in session...
<script type="text/javascript">
$(document).ready(function() {
$.getJSON("http://twitter.com/statuses/user_timeline/kaleeswaran14.json?callback=?", function(data) {
for(i in data) {
$('.scroll-hold').append('<div class="blog_twit"><div class="blog_twit_img"><img src="images/right1.png" border="0" alt="image"></div><div class="blog_twit_txt">'+data[i].text+'</div><div class="blog_twit_boder">'+parseTwitterDate(data[i].created_at)+'</div></div>');
}
});
});
function parseTwitterDate($stamp)
{
var date = $stamp;
return date.substr(0,16);
}
</script>
--
Thank you.
Regards,
Kaleeswaran.S
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment