Created
August 21, 2015 13:48
-
-
Save borsch/bf75d4f9d009d9c5f84c to your computer and use it in GitHub Desktop.
facebook make post with js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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