Access Your Twitter Profile Without Password using jQuery

Twitter has crawled to each and every web application these days. Everyone is extracting benefits fron twitter. You can also get some advantage from twitter API by accessing your profile details from twitter. In this tutorial I will show you how to access your Twitter account details in the most simple way using jQuery without requring your password.
Live Demo Download Script

jQuery Code

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(function()
{
$('#btn').click(function()
{
twitterusername = $('#uname').val();
if(twitterusername != '')
{
$('#loading').text('Please wait...');
$.getJSON('http://twitter.com/users/'+twitterusername+'.json?callback=?',
function(data)
{
$('#loading').empty();
$('.main').css({'background-image':'url('+data.profile_background_image_url+')'});
$('#twit_uname').html('<b>'+data.screen_name+'</b>');
$('#twit_loc').html('<b>'+data.location+'</b>');
$('#twit_frnd').html('<b>'+data.friends_count+'</b>');
$('#twit_url').html('<b>'+data.url+'</b>');
$('#twit_created').html('<b>'+data.created_at+'</b>');
$('#twit_name').html('<b>'+data.name+'</b>');
$('#twit_flwr').html('<b>'+data.followers_count+'</b>');
$('#twit_img').html('<img src="'+data.profile_image_url+'" height="50" width="50">');
$('#twit_bg').html('<img src="'+data.profile_background_image_url+'" height="100" width="100">');
});
}
});
})
</script>

HTML Code

<html>
<head>
<style>
div{float:right; border-bottom:1px dashed #909; margin-bottom:2px;}
li{border-bottom:1px dashed #909; margin-bottom:10px;}
.main{margin:auto; border:1px solid #CC0; float:none; width:520px; padding:10px; font-family:Verdana, Geneva, sans-serif; font-size:16px; color:#C39;}
b{float:left; text-align:left;}
</style>
</head>
<body>
<div class="main">
Enter your Twitter Username : <input type="text" name="user" id="uname">
<input type="button" value="Get my Profile" id="btn"><br />
<div id="loading" align="center"></div>
<ul>
<li>Name : <div id="twit_name"></div></li>
<li>Username : <div id="twit_uname"></div></li>
<li>Location : <div id="twit_loc"></div></li>
<li>Total Friends : <div id="twit_frnd"></div></li>
<li>URL : <div id="twit_url"></div></li>
<li>Account Created at : <div id="twit_created"></div></li>
<li>Followers : <div id="twit_flwr"></div></li>
<li>Profile Image : <div id="twit_img" style="border:1px solid #999999; height:50; width:50;"></div></li>
</ul>
</div>
</body>
</html>

Written by Arvind Bhardwaj

Arvind is a certified Magento 2 expert with more than 10 years of industry-wide experience.

Website: http://www.webspeaks.in/

3 thoughts on “Access Your Twitter Profile Without Password using jQuery

  1. hi again, i have a question, i have database of users & i want to save their data(followers) in every 5minutes, can i do that??

  2. Hi Priya,
    You can use setInterval() method of JavaScript for this purpose. In this method just call the function for saving the data.
    More programatically you can use cron jobs for your purpose.

Comments are closed.