Skip to content

Instantly share code, notes, and snippets.

@alexanderscott
Created January 1, 2013 23:35
Show Gist options
  • Save alexanderscott/4430984 to your computer and use it in GitHub Desktop.
Save alexanderscott/4430984 to your computer and use it in GitHub Desktop.
/* LIKE */
FB.Event.subscribe('edge.create', function(href, widget) {
alert('You just liked the page!');
});
/* FEED DIALOG FB.UI
http://developers.facebook.com/docs/reference/javascript/FB.ui/
http://developers.facebook.com/docs/reference/dialogs/
http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/
*/
FB.ui(
{
method: 'feed',
name: 'Facebook Dialogs',
link: 'http://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.');
}
}
);
/* FEED DIALOG
** Note that the below example assumes that the user is already logged in and has authorized your application.
*/
<div id='fb-root'></div>
<script src='http://connect.facebook.net/en_US/all.js'></script>
<p><a onclick='postToFeed(); return false;'>Post to Feed</a></p>
<p id='msg'></p>
<script>
FB.init({appId: "YOUR_APP_ID", status: true, cookie: true});
function postToFeed() {
// calling the API ...
var obj = {
method: 'feed',
redirect_uri: 'YOUR URL HERE',
link: 'https://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
name: 'Facebook Dialogs',
caption: 'Reference Documentation',
description: 'Using Dialogs to interact with users.'
};
function callback(response) {
document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
}
FB.ui(obj, callback);
}
</script>
/* FB ASYNC INIT
http://developers.facebook.com/docs/reference/javascript/
*/
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : 'YOUR_APP_ID', // App ID from the App Dashboard
channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File for x-domain communication
status : true, // check the login status upon init?
cookie : true, // set sessions cookies to allow your server to access the session?
xfbml : true // parse XFBML tags on this page?
});
// Additional initialization code such as adding Event Listeners goes here
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment