0
votes

I'm stuck with sharing and commenting Facebook posts from my website.

Look. In Twitter we can reply a tweet simply by a link

https://twitter.com/intent/tweet?in_reply_to=35782000644194304

or

we can retweet the tweet by this link

https://twitter.com/intent/retweet?tweet_id=35782000644194304

it's so easy, after clicking you redirecting to twitter where you can do this, and i like it.

With facebook posts it is not so easy. I have Facebook posts (copies of posts, i parsed them before and saved to my DB, ID of that posts I saved too) at my website and I'd like to share/comment/like this posts. Maybe Facebook have the links like twitter, or some another way to do it, I don't know, but i spend all day to find solution and I failed.

Maybe it is possible to create links like this:

http://facebook.com/ID_OF_THAT_FB_POST/share or http://facebook.com/ID_OF_THAT_FB_POST/comment

and.. after clicking the link, it redirects to facebook page, where you can share this post or comment?

2

2 Answers

1
votes

Well let me see if I understand, If you want to SHARE/COMMENT/LIKE a post on Facebook, from your website then you can use the Graph API, POST, connection section. https://developers.facebook.com/docs/reference/api/post/

This allows you to create a comment and a like, having the right access_token and the stream_publish permission.

Create: You can write to the POST_ID/comments connection to post a comment to the post by issuing an HTTP POST request with the publish_stream permission and following parameters.

So you have yo make an HTTP POST request to http://graph.facebook.com/POST_ID/comments?message=HELLO+WORLD&access_token=YOUR_ACCESS_TOKEN

same thing for the like:

make an HTTP POST request to http://graph.facebook.com/POST_ID/likes?access_token=YOUR_ACCESS_TOKEN

with Javascript SDK would be something like this :

var postID='POST_ID';
var msg = 'Comment this post';
FB.api('/'+postID+'/comments', 'post', { message: msg }, function(response) {
  if (!response || response.error) {
    alert('Error occured');
  } else {
    alert('Post ID: ' + response.id);
  }
});

If you want to share the there is no API documentation for that, but you can use something like this:

<script type="text/javascript">
function sharePost(){
 var page = 'https://www.facebook.com/permalink.php?story_fbid=POST_ID&id=PAGE_ID';
 var sharer= 'https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(page);
 var w=660;
 var h=460;
 var sTop=window.screen.height/2-(h/2);
 var sLeft=window.screen.width/2-(w/2);
 var sharer= window.open(sharer,"Share","status=1,height="+h+",width="+w+",top="+sTop+",left="+sLeft+",resizable=0");
 return false;
}
</script>

<a onclick="sharePOST()">SHARE POST</a>
0
votes

Do not think facebook yet has such kind of api, though you may look up the iframe url structure for any kind of social widget and try to play around. Here is the list you may look it up https://developers.facebook.com/docs/guides/web/#plugins. Take in consideration that share button is deprecated in favor of like. Also I would rather escape heavy code customization and trying to use API as much as it possible, this would help avoid future incompatibilities while facebook's evolution)