有没有办法在活动的墙上发布带有图片和链接的帖子?目前我只能发布状态(消息)。在用户的墙上没有这样的问题。我已经尝试了新的 Graph API 以及旧的 REST API('stream.publish' 方法)但没有成功(使用 PHP SDK)。先感谢您。
我用于 Graph API 的代码:
$attachment = array(
'message' => 'my message',
'name' => 'This is my demo Facebook application!',
'caption' => "Caption of the Post",
'description' => 'this is a description',
'picture' => 'link to an image',
'actions' => array(array('name' => 'See recipe',
'link' => 'http://www.google.com'))
);
$facebook->api('/'.$eventID.'/feed/','post',$attachment);
REST API 的代码:
$url = "https://api.facebook.com/method/stream.publish?".$access_token;
$attachment = array('name' => 'This is my demo Facebook application!',
'href' => 'http://news.google.com',
'description' => 'It is fun!',
'media'=> array(array(
'type'=> 'image',
'src' => 'link to an image',
'href' => 'http://www.google.gr'))
);
$params = array();
$params['message'] = "my message";
$params['attachment'] = json_encode($attachment);
$params['target_id'] = $eventID;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$result = curl_exec($ch);
curl_close($ch);
正如我上面提到的,如果我在用户的墙上发布,两者都可以工作。在事件的墙上发布状态消息,仅显示“消息”参数的内容。