Skip to content

Instantly share code, notes, and snippets.

@borsch
Created August 21, 2015 13:48
Show Gist options
  • Save borsch/bf75d4f9d009d9c5f84c to your computer and use it in GitHub Desktop.
Save borsch/bf75d4f9d009d9c5f84c to your computer and use it in GitHub Desktop.
facebook make post with js
<html>
<head>
<script src="https://connect.facebook.net/en_US/sdk.js"></script>
</head>
<body>
<script type="text/javascript">
var PAGE_ID = 'page_id';
var PAGE_ACCESS_TOKEN = 'access_tooken_to_page';
window.fbAsyncInit = function() {
FB.init({
appId : 'app_id',
xfbml : true,
version : 'v2.4'
});
FB.api(
PAGE_ID+'/feed',
'POST',
{
value: 'EVERYONE',
message: 'post message',
access_token: PAGE_ACCESS_TOKEN
},
function(response){
console.log(response);
if(response.error){
alert('error: '+response.error.error_user_msg)
} else {
var index = response.id.indexOf('_');
var post_id = index > -1 ? response.id.substr(index+1) : response.id;
alert('http://www.facebook.com/'+post_id);
}
}
);
};
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment