php 在来自 Facebook API 的状态更新中标记朋友

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4327353/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 12:41:29  来源:igfitidea点击:

Tagging friends in status updates from Facebook API

phpfacebookfacebook-graph-api

提问by Vinch

I recently came across this blog postthat said that it's possible to tag someone in a status update from a Facebook app (= from the API):

我最近看到这篇博客文章说可以在来自 Facebook 应用程序(=来自 API)的状态更新中标记某人:

However, it doesn't seem to work for me.

但是,它似乎对我不起作用。

It tried it in three different ways:

它以三种不同的方式进行了尝试:

$post = $facebook->api('/me/feed', 'post', array(
    'access_token' => $session['access_token'],
    'message' => 'Hello @[562372646:Lionel Cordier], how are you?'
));

or

或者

$access_token = $session['access_token'];
$message = 'Hello @[562372646:Lionel Cordier], how are you?';
$curl_post = 'access_token='.$access_token.'&message='.$message;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/me/feed');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curl_post);
$data = curl_exec($ch);
curl_close($ch);

or

或者

$access_token = $session['access_token'];
$message = 'Hello @[562372646:Lionel Cordier], how are you?';
$curl_post = 'access_token='.$access_token.'&status='.$message;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.facebook.com/method/users.setStatus');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curl_post);
$data = curl_exec($ch);
curl_close($ch);

But nothing works. The result I have is "Hello @[562372646:Lionel Cordier], how are you?" on my wall.

但没有任何作用。我的结果是“你好@[562372646:Lionel Cordier],你好吗?”在我的墙上。

But if I type "Hello @[562372646:Lionel Cordier], how are you?" directly in Facebook, it works correctly.

但是如果我直接在 Facebook 中输入“你好 @[562372646:Lionel Cordier],你好吗?”,它可以正常工作。

What am I doing wrong?

我究竟做错了什么?

采纳答案by Robarondaz

I was struggling with this problem last week and found the following bug report, which suggests (given the current ASSIGNED status) that it cannot be done yet:(

上周我一直在努力解决这个问题,并发现以下错误报告,这表明(鉴于当前已分配状态)还无法完成:(

http://developers.facebook.com/bugs/395975667115722/

http://developers.facebook.com/bugs/395975667115722/

回答by Debjit

Yes it is possible in this format: @[{user_id}:1:{name}]

是的,可以采用以下格式:@[{user_id}:1:{name}]

Try this tutorial: http://digitizor.com/2011/01/24/tag-user-facebook-graph/

试试这个教程:http: //digitizor.com/2011/01/24/tag-user-facebook-graph/

回答by mtariq

https://apps.facebook.com/profile_rankingis uploading a picture and you can tag people in pictures not in status messages.

https://apps.facebook.com/profile_ranking正在上传图片,您可以在图片中而不是状态消息中标记人物。

To Tag people in picture

在图片中标记人物

curl -F 'access_token=xxxxxx' -F 'url=https://appharbor.com/assets/images/stackoverflow-logo.png' -F 'message=@[100000891609024:Silient Killerz]' https://graph.facebook.com/me/photos

curl -F 'access_token=xxxxxx' -F 'url=https://appharbor.com/assets/images/stackoverflow-logo.png' -F 'message=@[100000891609024:Silient Killerz]' https://graph. facebook.com/me/photos

InGraph Api Explorer
Make the call post, set url to https://graph.facebook.com/me/photos,
Add field with key message and value @[100000891609024:Silient Killerz] (replace it with your friend id and name)
Add another field with key url and value https://appharbor.com/assets/images/stackoverflow-logo.png
click submit

Graph Api Explorer
Make the call post 中,将 url 设置为https://graph.facebook.com/me/photos
添加带有关键信息和值的字段@[100000891609024:Silient Killerz](将其替换为您的朋友 ID 和姓名)
添加另一个带有关键 url 和值的字段https://appharbor.com/assets/images/stackoverflow-logo.png
点击提交

回答by waseem

below code worked for me , try if you don't want to show place in post then use the same code i mentioned $params['place']='155021662189';that code won't show the place in Post

下面的代码对我有用,如果您不想在帖子中显示位置,请尝试使用我提到的相同代码$params['place']='155021662189'; 该代码不会在 Post 中显示该位置

             $params=array();       

             $params['message'] = "Hi Friends ";
             $params['tags']='12345678903,1234567654'; //comma separated friends ID's
             $params['place']='155021662189'; 

             $params['name'] = "Some namee";
             $params['link'] = "http://blaha.com";
             $params['description'] = "blah blah blah blah";
             $params['picture'] = "image link"; 
             $params['caption'] = "Join ";


            $shared=$facebook->api("/".$user['id']."/feed", "post", $params);
                         or 
                    $shared=$facebook->api("/me/feed", "post", $params);  

回答by Somnath Muluk

I have tried for hour but I think there needs to add new bug report. It was working year before as posted by Debjit.

我已经尝试了一个小时,但我认为需要添加新的错误报告。正如 Debjit 发布的那样,它是在前一年工作的。

You should make bug report to facebook. (If doesn't exist).

您应该向 facebook 提交错误报告。(如果不存在)。

Have updated on following posts:

更新了以下帖子:

  1. how to tag users in application post of a facebook application
  2. Tagging people in a Facebook Post?
  3. Tagging a user in a wall post/update using Facebook API
  4. How to let users tag their friends in a Facebook status update posted from a tab on a Facebook page?
  1. 如何在 Facebook 应用程序的应用程序帖子中标记用户
  2. 在 Facebook 帖子中标记人?
  3. 使用 Facebook API 在墙贴/更新中标记用户
  4. 如何让用户在从 Facebook 页面上的选项卡发布的 Facebook 状态更新中标记他们的朋友?