Skip to content

Instantly share code, notes, and snippets.

@optikalefx
Created September 11, 2012 22:04
Show Gist options
  • Save optikalefx/3702457 to your computer and use it in GitHub Desktop.
Save optikalefx/3702457 to your computer and use it in GitHub Desktop.
// Twitter Object
var Twitter = Social.inherit({
el : null,
api : "http://platform.twitter.com/anywhere.js?id=jU6TJqf8mVs4qEVidQdoWw&v=1.2",
_construct : function() {
if(location.hash && location.hash.indexOf("oauth_access_token") != -1) {
this.login();
}
},
login : function(e,el) {
var self = this;
$.getScript(this.api, function() {
twttr.anywhere(function (tw) {
// bind auth compelte event
tw.bind("authComplete", function (e, user) {
self.doLogin(user);
});
// app already connected
if(tw.isConnected && typeof tw.currentUser != "undefined") {
self.doLogin(tw.currentUser);
// app not connected yet
} else {
tw.signIn();
}
});
});
},
// twitter login action
doLogin: function(user) {
$.post("twitter/login",{
name : user.name,
location : user.location,
id : user.id,
profileImageUrl : user.profileImageUrl
},function(data) {
log("register data",data);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment