我使用以下方式成功向 Facebook 群组发布内容:
$post_url = '/' . $my_group_id . '/feed';
$msg_body = array('link' => urldecode($link), 'message' => 'New post:');
try {
$postResult = $facebook->api($post_url, 'post', $msg_body);
if (!$postResult) // handle error...
} catch (FacebookApiException $e) {
// handle error...
}
问题是:如何在 Facebook 中获得此新帖子的永久链接,以便我可以从其他网站指向它?
我可以通过检查 Facebook 中新帖子的属性来手动获取它,但是在上述成功发布后,如何在 PHP 代码内获取它呢?
最佳答案
如果您的 $postResult
中有此回复:
{
"id": "xxxx_xxxx"
}
永久链接将是“https://facebook.com/{id}”
,所以它是:
https://facebook.com/xxxx_xxxx
Facebook 将处理转发到您群组中的真实最终网址。
我使用 Graph API Explorer 对此进行了测试而且它似乎始终如一地工作。
关于PHP 获取 Facebook 帖子的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17818159/