阅读facebook提要帖子

时间:2019-01-01 22:03:31

标签: php facebook-php-sdk

我使用以下代码阅读我的Facebook提要:

<?php

require 'vendor/autoload.php';

$appId = "{my app id}";
$appSecret = "{my app secret}";

$fb = new \Facebook\Facebook([
  'app_id' => $appId,
  'app_secret' => $appSecret,
  'default_graph_version' => 'v3.1'
]);


$accessToken = {my access token};

$postData = "";
try {
    $userPosts = $fb->get("/{mypage}/feed", $accessToken);
    $postBody = $userPosts->getDecodedBody();
    $postData = $postBody["data"];
} catch (FacebookResponseException $e) {
    // display error message
    exit();
} catch (FacebookSDKException $e) {
    // display error message
    exit();
}

print_r($postData);
?>

这很好用,但结果数组只包含不带换行符的文本和图像(在原始帖子中)。 也不包含链接的You-Tube页面。

是否有可能获得帖子的所有内容?

我也想为每个帖子创建一个赞按钮。

打个招呼,谢谢你的帮助

丹尼尔

1 个答案:

答案 0 :(得分:1)

对不起,已经知道答案了。

改变

$userPosts = $fb->get("/{mypage}/feed", $accessToken);

$userPosts = $fb->get("/{mypage}/feed?fields=created_time,message,attachments", $accessToken);

解决了我的问题。

相关问题