I am trying to create a web-based Twitter app that will print out a friend's timeline, but the Twitter API asks for username/password. How do I do the username/password authentication on the server-side without asking this from the user. Does anyone know how to do this? Is there also a way to create a dynamic app that will update inside the web page whenever a new twitter update occurs?
Here is the code:
$(document).ready(function(){ $('#response').createAppend('img', { src: 'images/twitter-32x32.png', alt: 'Loading...', id: 'loading_image'}, null);
$.getJSON(url, ws_results);
});
function ws_results(obj) {
// hide the loading image
$('#loading_image').hide("slow");
// alternative way of displaying properties
// var property, propCollection = "";
// for (property in obj[0].user) {
// propCollection += property + "\n";
// }
// alert(propCollection);
$('#response').createAppend(
'table', { width: '600px', align:'center', border:'2', rules:'none', frame:'box', style: 'background:#FFF;' , Name: 'tableData', id: 'Tweets' }, [
'tr', { }, [
'th', { colspan: '2', align: 'left', style: 'background: #FFF; color: #000 ' }, [ 'img', { src: 'images/twitter-logo.jpg', align: 'left'} ]
]
]
);
// loop through items
for (var i = 0; i < obj.length; i++) {
// create table row
$('#Tweets').append('<tr id="row' + i + '"><\/tr>');
$('#row' + i).append('<td align="left" id="lcell' + i + '" style="font-size: 10pt;"><\/td>');
$('#row' + i).append('<td align="left" id="rcell' + i + '" style="font-size: 10pt;"><\/td>');
if (typeof(obj[i].user.url) == "undefined" || obj[i].user.url == '')
{
$('#lcell' + i).createAppend('img', { src: obj[i].user.profile_image_url, Name: 'ProfileImg', align: 'left', hspace: '5', alt: obj[i].user.name }, null);
}
else
{
$('#lcell' + i).createAppend('a', { href: obj[i].user.url }, [ 'img', { src: obj[i].user.profile_image_url, Name: 'ProfileImg', align: 'left', hspace: '5', alt: obj[i].user.name }, null]);
}
$('#rcell' + i).createAppend('a', { id: 'Twit', title: obj[i].user.name, href: 'http://twitter.com/' + obj[i].user.screen_name }, obj[i].user.screen_name );
$('#rcell' + i).append(' ' + obj[i].text + ' ');
$('#rcell' + i).append('<span id="created_at">' + obj[i].created_at + '<\/span>');
$('#rcell' + i).append(' from ' + obj[i].source);
}
}
//]]>
</script>