You Are Here: Home » Facebook » Programming

How To @ Tag An User While Publishing A Post Via Facebook Graph API

By Debjit on January 24th, 2011 
Advertisement

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.

Tag Friends on Facebook via Graph API

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:

Tag Users in Facebook posts via Facebook Graph API

Tag Users in Facebook posts via Facebook Graph API from 3rd party app

And here is the full code snippet:

$uid = "1234567890"; //User's Facebook ID, set the value as "me" if publishing on logged in user's wall
$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;
}
--
If you are facing any problem with the implementation do write to me at: [email protected]. You can also hire me for developing Facebook applications for you.

Advertisement







How To @ Tag An User While Publishing A Post Via Facebook Graph API was originally published on Digitizor.com on January 24, 2011 - 1:17 am (Indian Standard Time)