Post Comment with Friends User Tag - facebook

i wan't to Post a comment on a Page Post.
No Problem works finde with:
FB.api('/MY_ID_FROM_PAGE_POST/comments', 'POST', {message: 'test'}, function(resp){});
now i want to tag a user.
I try it with the notifications notation. Like:
{
message: 'test #[AVnA0866TTQbPZuYWv1vZlCEBZBEUIbFskwYZ6DEFEesHck54azfmccyw0YA5w129Q2dOey64hgXNdOLJhCZUo_3J-EHEZwS4lIzPm2egWsSZQ]'
}
Couse of Api Verison 2 i did not become the real user id. I only become this string as a id for the users. Does someone has a solution for this problem?

Have you used the example on taggable_friends, as shown here: https://developers.facebook.com/docs/opengraph/using-actions/v2.0#mentions
You should first receive the ids of the users you can tag using user/taggable_friends endpoint. Then you can use those IDs in the post you create.
Does that work?

Related

How facebook auto detect the post and comment id?

I was playing with facebook graph api, where I wanted to get the posts by me and it's related comments.
I get all posts of using me/posts/ and the id of each post is appended with the user-id i.e if my user-id is 1234 then the list of post would be like (JSON):
{
id:1234_50
}
{
id:1234_51
}
{
id:1234_53
}
And now if I copy the post-id and paste it to facebook.com/1234_53 then it redirects me to that post. Ok that's fine, facebook identifies that the left part of _ is user-id and right is post-id.
But when I dive some more deeper and query the api for the comments of posts using <post-id>/comments, it returns me the metadata for comments. Again each comment has a unique id. Suppose post 53 has a comment having id= 777. So the JSON returned for that is id:53_777. Now when I append this to facebook.com/53_777, this time api identify the left part of _ as the post id and the right part as the comment id.
I am curious to know how api working differently in above scenarios?
NOTE: I am thinking all this in an RDBMS perspective where user, posts and comments must be having separate tables
you can use :
me/posts/?fields=comments{id}

Messenger Bot for comments

I am trying to make bot using facebook messenger api. My bot is working perfectly for direct messages. Now i want to add a feature called comment bot. Like when someone comments on my page post. I would like my bot to reply to the person. I added a webhook url for feeds. When some one comments in a post i get a respone similar to the following:
{"changes":[{"field":"feed","value":{"item":"comment","sender_name":"6sense","comment_id":"127569201201434_137925500165804","sender_id":126557694635918,"post_id":"126557694635918_127569201201434","verb":"add","parent_id":"12655769463
5918_127569201201434","created_time":1507031347,"message":".."}}],"id":"126557694635918","time":1507031349}
Now from that webhook, i am trying to reply back to user using the sender_id. But i am getting a long error which is in short
{ error:
{ message: '(#100) No matching user found',
type: 'OAuthException',
code: 100,
error_subcode: 2018001,
fbtrace_id: 'EmEDxfdcnyF' } } }
I saw some sites implementing this feature. So i guess its possible. But i am not sure why its not working. I am using the same app for this.
Try private_replies API with comment_id to send private replies to user.
To use this API you need read_page_mailboxes permission.

How to comment on embedded facebook post on a website without leaving it

I recently made a fanpage and i have used embedded code from one of the post of my fanpage to my website.
So now It shows the post on my website and number of likes but i would like to show current existing comments which that particular post had got. Right now it is just displays the comment button and if i will click that then it will take me to the fanpage just for the sake of comment.
So heres what i need
1 - Comment on the embedded post without leaving the website to facebook.
2 - Displaying all the current existed comments ..
the image right now look like this
Thats very simple. First, you need to login user and ask for publish_stream permission. After the user is logged in, you just to display a button that triggers the function named comment, passing the ID (corresponding to the object user is going to comment to) .
You will also need an input field for inserting the comment (of course), and using jquery .value we will get the value of the input field .
PS: Specify NAME and ID on the message input field. I dont remember wich one is, put both of them .
After getting the variables, we will call FB.api, specifing the variables id and comentario than get the response for handling the result (if you want), you can try to reload the comment plugin, or refreshing the page .
function comment(id) {
var id = id;
var comentario = document.getElementById("message").value;
FB.api("/"+id+"/comments","POST",
{
"message": comentario
},
function (response) {
if (response && !response.error) {
alert('Comentado !');
} else {
alert('Erro !');
}
});
$("#atividade").html('COMENTADO');
}
That is very simple and fun, but you will need to get authorization from facebook platform to ask users for publish_stream permissions before production .
I think David's answer will just post a new comment, not show all post's comments.
Unfortunately there is not a option to show the comments on embed posts.
You need to get the post id, call a api to load all comments and so embed each one of them. Yeah, that's terrible...
Open the graph api explorer:
https://developers.facebook.com/tools/explorer/
Type {post-id}/comments on GET input and send it to see a response example.
And that's how you embed comments:
https://developers.facebook.com/docs/plugins/embedded-comments
I don't think loading all comments from all posts will have a good performance. I suggest you to create a button "see comments" which call the api. After that you can create the input text for new comments, like David said.

Adding a Facebook comment on a URL and have it displayed on user profile

I am creating a web application that displays a list of images taken from Flickr and I would like a user to login through Facebook and allow them to comment on those images. I was able to get the login/authentication working but I am now having trouble to enable a user to add a comment (as oppose to a Facebook 'post') on a Flickr image and have this activity show up on the user's Facebook profile/feed (i.e "John Smith commented on a link").
Here is what I have so far:
var fbCommentApi = '/me/myappname_ns:comment?access_token=' + fbUserToken + '&method=post' + '&picture=[WEBSITE_URL]' + selectedItemId;
FB.api(
fbCommentApi,
'post',
{ message: txtObj.value },
function (response) {
if (!response || response.error) {
alert("Sorry, there was a problem. Please try again later. [API]");
}
else {
alert("Thank you. Your comment will appear shortly");
hideCommentBox(txtObj);
}
}
);
The above code doesn't create a comment but instead it creates a post on the user's timeline with the URL attached. So when I try to retrieve comments for the WEBSITE_URL item through Facebook Graph...
'https://graph.facebook.com/comments/?id=[WEBSITE_URL]' + itemID
...I end up with empty data being returned.
I have an Action Type called 'Comment' in my Facebook app and that's the action I am using when trying to add the comment.
Thanks in advance and I look forward to your answers.
UPDATE 1: It seems now that if I use Facebook Graph this way.. graph.facebook.com/me/appname_ns:discuss?access_token=[TOKEN]&website=[URL]&met‌​hod=post
..it would just add an entry to the user's Activity box in their timeline, I didn't even pass a comment or message parameter to the URL as a query string parameter. That could be part of the problem.
UPDATE 2: According to another StackOverflow question, there seems to be no way to get a view of all actions done by all users, it has to be done per user (an API call per user). Therefore another way of handling this particular issue is to save the comments (or whatever action performed) to our own database.
Well, an Open Graph action is not a comment, even if you name it comment …
If you want a real Facebook comment, then either get a reference to an object that actually can be commented upon; or substitute comment with post/link post.

Tagging friends in a fb.api status update?

Is it possible to tag friends somehow using the Facebook fb.api (JavaScript SDK) call?
By tagging I mean what happens when you use "#" in the regular facebook.com UI.
It is currently not possible to tag a friend in a status update or post via the API.
Not sure if that's what you are asking, but the syntax to tag a friend using Facebook API is #[uid:friend name]. However, it seems like there is a bug at the moment and FB does not support it.
Check the Facebook documentation for more information about this: photos.addTag.
Quote:
Each tag in the list must specify: "x", "y", and either the user id "tag_uid" or free-form "tag_text" identifying the person being tagged. An example of this is the string {"x":"70.0","y":"70.0","tag_text":"some person"}
And read in FB.api on how to use the REST API calls using JavaScript.
Yes, you can use FB.api to tag a friends.
E.g. If you would like to a tag a friend(s) withing a message that you will share on a Fb's wall you have to do following.
1) Get extended permissions ('publish_stream') e.g. you can request it while login to the app FBUser.login({scope: 'publish_stream'});
2) You have to pass a string with the facebook_user_id to a 'tag' key of the api object. e.g.
FB.api('me/feed', 'post', {
message: "my message here",
place: '123456789', // mandatory!!!
tags: "123456, 654321, 147258, 852963", // facebook users ids of your friends
name : "Some text here",
description : "Some text here",
picture: "http://wwww.link.to/the_image"})