简体   繁体   中英

Using Facebook's '@' to tag an User while publishing a post via Facebook Graph API / PHP SDK

I managed to create a Facebook App using PHP. The visitor uploads the photo from my website. Under each photo there is my custom message. Below is the code:

$args = array(
'message'=> "This picture is brought to you by Miss Little Girl",
'image' => '@' . $img,

I want the message to include the Username of the person who uploaded the picture, and I manged to find this code:

$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;
}

Unfortunately I haven't managed to integrate the code below to the one above it. Can you please help me? When I tried to integrate it "Happy Birthday, @[".$uid.":1:".$ufname."]!",

How can I display the username of the person of the person instead of the $uid can you please provide me with sample PHP code please?

Thanks.

not every user has a username, anyway if user has a username, you can get it this way:

$user = $facebook->api('/'.$uid);
$username = isset($user['username']) ? $user['username'] : '';

by the way, how you get the user id and user name? I think you already have user object

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM