简体   繁体   English

通过Facebook Graph API / PHP SDK发布帖子时,使用Facebook的“ @”标记用户

[英]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. 我设法使用PHP创建了一个Facebook App。 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."]!", 当我尝试将其集成为“生日快乐,@ [“。$ 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? 我如何显示此人的用户名而不是$ uid,请您提供示例PHP代码?

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? 顺便问一下,您如何获得用户ID和用户名? I think you already have user object 我认为您已经有用户对象

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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