Skip to content

Instantly share code, notes, and snippets.

@rajib
Created August 20, 2010 12:13
Show Gist options
  • Save rajib/540181 to your computer and use it in GitHub Desktop.
Save rajib/540181 to your computer and use it in GitHub Desktop.
Twitter = function () {
// user credentials
var username, password;
function make_basic_auth(user, password) {
var tok = user + ':' + password;
var hash = Base64.encode(tok);
return "Basic " + hash;
}
return {
login: function () {
username = $('#username').val();
password = $('#password').val();
var auth = make_basic_auth(username, password);
var url = "http://twitter.com/account/verify_credentials.json";
$.ajax({
url: url,
method: 'GET',
dataType: 'json',
beforeSend: function (req) {
req.setRequestHeader('Authorization', auth);
},
success: function (json, textStatus) {
alert("Login Success");
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("Login Failed");
}
});
}
}
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment