I want to implement twitter on a website, so I can sign in with a
custom user name and password to receive my own tweets.
I found some code on the Appcelerator community, but I have no idea
how to use javascript,
Could anyone help me please?
<html>
<head>
<title>Twitter Demo</title>
<style>
.section
{
border:1px solid #ccc;
-webkit-border-top-right-radius: 5px;
-webkit-border-top-left-radius: 5px;
-webkit-border-bottom-right-radius: 5px;
-webkit-border-bottom-left-radius: 5px;
padding:10px;
color:#777;
margin:10px;
}
</style>
</head>
<body style="font-family:'Helvetica Neue'">
<div class="section" style="height:50px;text-align:center">
<img src="twitter.png"></img>
</div>
<div style="height:150px;padding-top:30px;" class="section">
<div style="height:50px;float:left;margin-right:10px">
Username:
</div>
<div style="float:left">
<div id="textfield1" style="height:50px;width:170px"></div>
</div>
<div style="clear:both;margin;top:10px"></div>
<div style="height:50px;float:left;margin-right:10px">
Password:
</div>
<div style="float:left">
<div id="textfield2" style="height:50px;width:170px"></div>
</div>
<div style="clear:both;margin;top:10px"></div>
<div style="margin-left:80px;">
<div id="button"></div>
</div>
</div>
<div class="section" style="height:40px;text-align:center">
This is a demo that logs you in to twitter and displays your
messages.
</div>
<script>
var height = (Titanium.Platform.name.indexOf('iPhone') != -1) ? 30:
40;
var tf1 = Titanium.UI.createTextField({
id:'textfield1',
value:'',
keyboardType:Titanium.UI.KEYBOARD_EMAIL,
hintText:'enter username',
width:170,
height:height,
clearOnEdit:true,
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED,
clearButtonMode:Titanium.UI.INPUT_BUTTONMODE_ALWAYS,
});
var tf2 = Titanium.UI.createTextField({
id:'textfield2',
value:'',
keyboardType:Titanium.UI.KEYBOARD_ASCII,
hintText:'enter password',
width:170,
height:height,
clearOnEdit:true,
passwordMask:true,
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED,
clearButtonMode:Titanium.UI.INPUT_BUTTONMODE_ALWAYS,
});
var button = Titanium.UI.createButton({
id:'button',
title:'Login',
color:'#336699',
height:32,
width:100,
fontSize:12,
fontWeight:'bold'
});
button.addEventListener('click',function()
{
// hide the keyboards if they're showing
tf1.blur();
tf2.blur();
var un = tf1.value;
var pw = tf2.value;
var activityIndicator = Titanium.UI.createActivityIndicator();
Titanium.UI.currentWindow.setRightNavButton(activityIndicator);
var url = "http://"+un+":"+pw+"@twitter.com/statuses/
friends_timeline.json?count=50";
var xhr = Titanium.Network.createHTTPClient();
xhr.onload = function()
{
var json = eval('('+this.responseText+')');
var data = [];
for (var c=0;c<json.length;c++)
{
var row = json[c];
var bgcolor = (c % 2) == 0 ? '' : 'background-color:#eee';
var html = "<div style='position:relative;padding:0;height:
80px;"+bgcolor+"'>";
html += "<div style='position:absolute;left:0;top:5px;border:2px
solid #999;'><img src='"+row.user.profile_image_url+"'/></div>";
html+='<div style="position:absolute;top:6px;left:60px;height:
70px;font-size:11px;">'+row.text+'</div>';
html+="</div>";
data[c] = {html:html};
}
var tableView = Titanium.UI.createTableView({data:data,rowHeight:
80},function(){});
Titanium.UI.currentWindow.addView(tableView);
Titanium.UI.currentWindow.showView(tableView);
var close = Titanium.UI.createButton({title:'Logout'});
Titanium.UI.currentWindow.setRightNavButton(close);
close.addEventListener('click',function()
{
Titanium.UI.currentWindow.close();
});
};
xhr.open("GET",url);
xhr.send();
});
</script>
</body>
</html>