Tagging friends in a fb.api status update? - facebook

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"})

Related

How to get Instagram post URL from Facebook Graph media_id

I'm using Instagram Mentions API and was able to obtain FB media_id for couple Instagram posts.
I need media_id to get post content via /user/mentioned_media. Unfortunately that endpoint does not provide ig_id or shortcode or permalink which I need.
Is there a way to get Instagram Post URL with FB Graph API media_id?
It seems like you can get media metadata (and all comments/replies) when someone #-mentions you in a non-owned-media comment by using a query like below.
You would use your own instagram business account id for the first number (the path component), and you'd use the comment_id you received from the webhook comment-mention notification as the second number:
/12345678901234567890?fields=mentioned_comment.comment_id(9876543210987654321){id,text,username,timestamp,media{id,media_type,media_url,permalink,username,like_count,comments_count,comments{id,text,username,user{id,username},like_count,timestamp,replies{id,text,username,user{id,username},like_count,timestamp}}}}
Yes, there is a way you can get Instagram post URL associated with a media if you know the media id.
You can also get more information (all its fields and edges) on media. See the docs here
You can get the Instagram post URL by making a GET request to /{ig-media-id}
Sample Request:
GET https://graph.facebook.com/v15.0/{{media_id}}?fields=permalink, shortcode&access_token={{ACCESS_TOKEN}}
Sample Response:
{
"permalink": "https://www.instagram.com/p/Clxsi5Pol2_/",
"shortcode": "Clxsi5Pol2_",
"id": "17xxx59557977xxx"
}
The value of the permalink is the valid public URL for the post.
You can also use the shortcode returned to construct the URL by concatenating the shortcode to https://www.instagram.com/p/.

Commenting on Facebook Page Ratings (Reviews) via Graph API

Long time lurker first time poster...
We are working with Facebooks API's to integrate into our web application and we are able to pull a Companies Page Rating via the {open_graph_story} parameter in the {page-id}/ratings section, however we cannot find a way to comment/reply to the rating. The documentation states:
"If a person has rated your page and a story has been generated, you can follow up with the person by posting to the story's comment node." (https://developers.facebook.com/docs/graph-api/reference/v2.0/page/ratings)
however when we pull the variables we retrieve no ID to reference for a comment. This is what we receive back from our authenticated account:
"data": [
{ "created_time": "2014-07-16T05:52:50+0000", "reviewer": { "id": "100000237096397", "name": "Romey Salazar" }, "rating": 5, "review_text": "Great job guys!!!!" } ],
Does anyone know how to retrieve the id for the rating itself so we can append a comment via API? Or some other way to reply/comment to a FB Page Rating?
Thanks!
When you have some ratings/review comments on your page and if you want to post comment to individual review comments as the Page Owner, you can follow the steps below.
1) Below request returns the json object of rating and reviews.
https://graph.facebook.com/v2.9/{YOUR_PAGE_ID}/ratings?field=open_graph_story&access_token={YOUR_PAGE_ACCESS_TOKEN}
The response json will contain ID field for each and every rating/review comments.
2) Using the ID, trigger the below request to post a comment on the rating as the Page Owner. You will need Page access token with manage_pages and publish_pages privilege.
https://graph.facebook.com/v2.9/{ID_OF_THE_RATING}/comments?message=Thanks for your rating&access_token={YOUR_PAGE_ACCESS_TOKEN}
These requests can be tested using Facebook Graph API Explorer
You need to request the open_graph_story field with the ratings endpoint. This will return the open_graph_story data which includes an id. You can then post to the comments endpoint of this story.
You have to make http get request on
https://graph.facebook.com/v2.9/{PageID}/ratings?fields=open_graph_story&access_token={PageAccessToken}
to get detailed response.
Make sure the parameter is "fields" not "field"

Redirect to profile page using facebook api

I need to create module for website which display feeds from client.
I had get feed from facebook using graph api of fb. But when i click on the profile name it says profile is not available.
This issue is occuring because facebook has moved to graph api 2 and in this version user is returned on basis on app which is diffrent from actual user id.
So if i need to redirect page from the website. How can i implement this?
Thank you for your time.
You can use the link field of the User object like this:
/me?fields=id,first_name,last_name,link
The result will be similar to the following:
{
"id": "10152055263451244234",
"first_name": "TheFirstName",
"last_name": "TheLastName",
"link": "https://www.facebook.com/app_scoped_user_id/10152055263451244234/"
}
Or, if you already have a app-scoped user_id, you can construct the link manually by
"https://www.facebook.com/app_scoped_user_id/" + {user_id} + "/"

Post Comment with Friends User Tag

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?

Check if user can write on a friend's Wall

If there any way to check in PHP SDK if user can write on specific friend's Wall?
Example:
if ($facebook_can_write_to->'123456789') echo "You can write on this friend's Wall";
Using the FQL table (http://developers.facebook.com/docs/reference/fql/user/) you can check to see if the current user can post to a friends wall by loading up the friend's user information specifically the can_post field.
can_post bool Whether or not the viewer can post to the user's Wall.
According to the documentation you can post on a user friends wall if that user granted you the *publish_stream* permission:
publish_stream
Enables your app to post content, comments, and likes to a user's
stream and to the streams of the user's friends.
There are some cases in which you won't be able to do so, for example if some user blocked your application then I guess it will fail if you try, so you should just check the response you get back from facebook for the api request and see if it worked or not.
Edit
As far as I'm aware you can not ask the api (nor via fql) "can my application post to this users wall", you can only ask "have this user granted my application the publish_stream permission".
If I understand what you want, I might have kind of a solution for you though.
I say show the user the option to post on a friends wall.
When the user chooses this option try to post on the friends wall (and I assume you are using ajax for that call), if it fails return some kind of code, then in the client side check for that code, if it returns use the javascript sdk to open a dialog.
You have two choices for dialogs, you can use the Feed Dialog like this:
var obj = {
method: 'feed',
to: "FRIEND_ID",
name: 'A message',
caption: 'Just trying something',
description: 'This is how to post on a friends wall'
};
FB.ui(obj, function(response) { console.log(response); });
Or you can use the Send Dialog:
FB.ui({
method: 'send',
to: "FRIEND_ID",
name: 'A message',
link: 'LINK_URL',
});
With this one though you have to post a link, I'm not sure if that works for you. After you tried and failed for a user you can save that data and use it later.