Skip to content

Instantly share code, notes, and snippets.

@7studio
Created October 13, 2017 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 7studio/d769a4c09c25cd4272a50106751dfde0 to your computer and use it in GitHub Desktop.
Save 7studio/d769a4c09c25cd4272a50106751dfde0 to your computer and use it in GitHub Desktop.
FACEBOOK, POST TO WALL, PUBLISH_STREAM, JAVASCRIPT, SDK
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<link rel="stylesheet" type="text/css" href="">
<script type="text/javascript">
</script>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : '496326720437274', // App ID from the app dashboard
channelUrl : '//local.facebook-test/channel.html', // Channel file for x-domain comms
status : true, // Check Facebook Login status
xfbml : true, // Look for social plugins on the page
oauth : true // Enable oauth authentication
});
// Additional initialization code such as adding Event Listeners goes here
FB.login(function(response)
{
if (response.authResponse)
{
console.log(response.authResponse.accessToken);
/* SHARE STYLE POST TO WALL - START */
// var opts = {
// message : 'Post message',
// name : 'Test post to wall',
// link : 'http://jonmosley.co.uk',
// description : 'Description here',
// picture : 'http://static.dezeen.com/uploads/2013/03/dezeen_Sergio-concept-car-by-Pininfarina_ss_4.jpg'
// };
// FB.api('/me/feed', 'post', opts, function(response)
// {
// if (!response || response.error)
// {
// console.log(response.error);
// alert('Posting error occured');
// }else{
// alert('Success - Post ID: ' + response.id);
// }
// });
/* SHARE STYLE POST TO WALL - END */
/* LARGE PHOTO STYLE POST TO WALL - START */
var opts = {
message : 'Photo upload',
access_token: response.authResponse.accessToken,
url : 'http://static.dezeen.com/uploads/2013/03/dezeen_Sergio-concept-car-by-Pininfarina_ss_4.jpg'
};
FB.api('/me/photos', 'post', opts, function(response)
{
if (!response || response.error)
{
console.log(response.error);
alert('Posting error occured');
}else{
alert('Success - Post ID: ' + response.id);
}
});
/* LARGE PHOTO STYLE POST TO WALL - END */
}else{
alert('Not logged in');
}
}, { scope : 'publish_stream, user_photos, photo_upload' });
};
// Load the SDK asynchronously
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment