Skip to content

Instantly share code, notes, and snippets.

@dhigginbotham
Last active December 11, 2015 23:19
Show Gist options
  • Save dhigginbotham/4675891 to your computer and use it in GitHub Desktop.
Save dhigginbotham/4675891 to your computer and use it in GitHub Desktop.
var _s
, FacebookConnect = {
settings: {
status: null,
me: null,
login: $('#facebook-auth'),
share: $('#facebook-share')
},
init: function() {
_s = this.settings;
this.bindUILoginStatus();
this.bindUIAppReq();
},
bindUILoginStatus: function() {
_s.login.live('click', function() {
FacebookConnect.getLoginStatus();
});
},
bindUIAppReq: function() {
_s.share.live('click', function(){
FacebookConnect.sendAppInviteRequest();
});
},
//check the login status, otherwise do some stuff
getLoginStatus: function() {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated
_s.status = response.authResponse;
FacebookConnect.getUserInfo();
console.log('User is connected');
} else if (response.status === 'not_authorized') {
FacebookConnect.userLogin();
console.log('User is not connected');
// the user is logged in to Facebook, no authy
} else {
console.log('User is not logged into Facebook');
// the user isn't logged in to Facebook.
}
});
},
//send app invite
sendAppInviteRequest: function(to) {
FB.ui({
method: 'apprequests',
to: to,
message: 'You should learn more about this awesome site.',
data: 'tracking information for the user'
});
return false;
},
//get user info
getUserInfo: function() {
FB.api('/me', function(resp) {
_s.me = resp;
});
},
//run user login modal
userLogin: function() {
FB.login(function(response) {
if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, {scope: 'email,user_likes,user_activities,user_location'});
},
//post to the feed dialog
feedDialog: function() { //needs to accept object of property metadata
FB.ui(
{
method: 'feed',
name: 'Facebook Dialogs',
link: 'https://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
caption: 'Reference Documentation',
description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
},
//send a message to ur friend
sendMessage: function() { //make accept title / link later
FB.ui({
method: 'send',
name: 'People Argue Just to Win',
link: 'http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html',
});
}
};
//fireworks!
(function() {
FacebookConnect.init();
// console.log(FB.getAccessToken());
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment