How To @ Tag An User While Publishing A Post Via Facebook Graph API
One of the most popular features on Facebook is tagging people in photos, videos, notes, status updates and other posts. It just helps you connect better with friends when you describe something on Facebook. So whenever you want to tag a friend on Facebook, just include the "@" symbol and as you type the name, a drop-down menu will appear that allows you to choose from your list of friends.
So, wouldn't it be good if you could incorporate the @ Tagging feature in your Facebook applications and have the @friend_name to be linked to an user's profile. In this article we will tell you how to @ Tag an user while publishing a post via Facebook Graph API.
In order to have @ Tag to an user's profile while publishing a post via Facebook Graph API, you have to include this code format in the message that you want to be published. (Thanks Takwing)
@[{user_id}:1:{name}]
So if you want to tag an user with the ID 1234567890, having name Nikka Mormola, you have to include the following in your message tag:
@[{1234567890}:1:{Nikka Mormola}]
Here is a screen shot of the @Tag process that has been achieved via the Graph API:
And here is the full code snippet:
$ufname = "Nikka Mormola"; // User's Full name on Facebook
$attachment = array(
'message'=> "Happy Birthday, @[".$uid.":1:".$ufname."]!",
);
try {
$post = $facebook->api('/'.$uid.'/feed', 'post', $attachment);
print_r($pp); //show the tagged post ID
} catch (FacebookApiException $e) {
//Error
exit;
}