laravel Facebook API 从提要获取帖子详细信息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33524239/
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-09-14 12:38:17  来源:igfitidea点击:

Facebook API get post details from feed

phpfacebooklaravel

提问by Miguel Stevens

I'm using the PHP Facebook API (together with laravel)

我正在使用 PHP Facebook API(与 Laravel 一起使用)

I can manage to get the feed from a page, with all it's post using

我可以设法从一个页面获取提要,所有它的发布都使用

    $request = Facebook::get('/COMPANYPAGE?fields=feed.limit(25)');
    $response = $request->getGraphPage()->getField('feed');

This returns the following objects

这将返回以下对象

enter image description here

在此处输入图片说明

But I can't seem to get the specific information for that post! Like the images included.. Is there another call I need to perform?

但是我似乎无法获得该帖子的具体信息!就像包含的图像一样......我需要执行另一个调用吗?

I tried the following but it's giving me back the same results

我尝试了以下但它给了我相同的结果

    $request = Facebook::get('/elbeko?fields=feed.limit(25)');
    $response = $request->getGraphPage()->getField('feed');

    foreach($response as $item) {
        $post = Facebook::get($item['id'])->getGraphObject();
    }

回答by Tobi

From v2.4 on, you have to specify each field you want to have returned from the Grpah API. You should be able to use

从 v2.4 开始,您必须指定要从 Grpah API 返回的每个字段。你应该可以使用

/elbeko/feed?fields=id,message,link,attachments{media}&limit=25

which returns something like

它返回类似的东西

{
  "data": [
   {
      "id": "1472127519670095_1645415342341311",
      "message": "Benieuwd naar ons nieuw project in de regio Gent? Binnenkort meer info via www.elbeko.be!",
      "link": "https://www.facebook.com/elbeko/photos/a.1589552831260896.1073741835.1472127519670095/1645415342341311/?type=3",
      "attachments": {
        "data": [
          {
            "media": {
              "image": {
                "height": 405,
                "src": "https://scontent.xx.fbcdn.net/hphotos-xpl1/v/t1.0-9/s720x720/11954813_1645415342341311_5204470874884096944_n.jpg?oh=0a7e10b12d3feb90b2de79fa60a7f8f8&oe=56C30337",
                "width": 720
              }
            }
          }
        ]
      }
    }
  ],
  "paging": {
    "previous": "https://graph.facebook.com/v2.5/1472127519670095/feed?fields=id,message,link,attachments%7Bmedia%7D&limit=2&format=json&since=1441790055&access_token=&__paging_token=&__previous=1",
    "next": "https://graph.facebook.com/v2.5/1472127519670095/feed?fields=id,message,link,attachments%7Bmedia%7D&limit=2&format=json&access_token=&until=1441124382&__paging_token="
  },
}

See

In the past, responses from Graph API calls returned a set of default fields. In order to reduce payload size and improve latency on mobile networks we have reduced the number of default fields returned for most Graph API calls. In v2.4 you will need to declaratively list the response fields for your calls.

过去,Graph API 调用的响应会返回一组默认字段。为了减少有效负载大小并改善移动网络的延迟,我们减少了为大多数 Graph API 调用返回的默认字段的数量。在 v2.4 中,您需要以声明方式列出调用的响应字段。