如何使用PHP中的Graph API在message_tags字段中发布消息

时间:2011-12-02 02:47:21

标签: php post facebook-graph-api

我想使用Graph API发布带有message_tags的消息。

我在PHP中确认仅发布消息,但不使用message_tags ..

这是示例代码。

---------
<?php
require_once('facebook.php');

$facebook = new Facebook(array(
  'appId'  => '127916833975***', // masked
  'secret' => 'a3271136ad68587d8e83171148f93***' // masked
));

$request_params = array('message' => mb_convert_encoding('test posting message', 'UTF-8', 'EUC-JP'));

$tags = array(
          'id' => '100000834278***', // masked
          'name' => 'MY_FRIENDS_NAME', // masked
          'offset' => 0,
          'length' => 15 // friend name length
        );

$request_params['message_tags'] = $tags;
$facebook->api('/feed', 'POST', $request_params);
?>
---------

在文档message_tags字段中,

---------
object containing fields whose names are the indexes to where objects are 
mentioned in the message field; each field in turn is an array containing 
an object with id, name, offset, and length fields, where length is the 
length, within the message field, of the object mentioned
---------

https://developers.facebook.com/docs/reference/api/post/

允许的范围是read_stream和publish_stream。

2 个答案:

答案 0 :(得分:4)

显然message_tags只能通过API阅读。不支持写message_tags。从2011年11月22日起查看此bug report and facebook response

答案 1 :(得分:-4)

添加此行代码以自动将邮件发布到墙上

if ($user) {
    $attachment =  array(
        //'access_token' => $access_token,
        'message' => "Amazing stuff by I just took part in their  by dragging and dropping items I would like to win, and who knows, I could get lucky!",
        'name' => "",
        'link' => "http://www.facebook.com/abc?sk=app_111111111111",
        'description' => "Pick your  and you could actually win all the items that you pick!",
        'picture'=> "http://www.abc.in/img/dp.png"
        );
    //var_dump($attachment);
    $facebook->api('/me/feed', 'POST', $attachment);
}