0

I have prepared a FB feed to my website using graph API. I have this code:

require 'Facebook/autoload.php';

$fb = new Facebook\Facebook([
    'app_id' => 'xxx',
    'app_secret' => 'xxx',
    'default_graph_version' => 'v2.10'
]);

$access_token = 'xxx';
$fb->get('xxx?fields=id,posts,photos', $access_token);

The result is

Facebook\FacebookResponse Object
(
    [httpStatusCode:protected] => 200
    [headers:protected] => Array
        (
            ...
        )

    [body:protected] => {...}
    [decodedBody:protected] => Array
        (
            [id] => xxx
            [posts] => Array
                (
                    [data] => Array
                        (
                            [0] => Array
                                (
                                    [created_time] => 2017-10-24T08:31:36+0000
                                    [message] => ...
                                    [id] => XXX_YYY
                                )

                            [1] => Array
                                (
                                    [created_time] => 2017-10-23T19:31:16+0000
                                    [message] => ...
                                    [id] => XXX_YYY
                                )

                            [2]=> Array ...

Each post has own ID in format 'XXX_YYY'. When I go to facebook.com/XXX_YYY, I see the post detail including images which were added to this post (one or more). In returned values above the images are ignored.

In Graph API Reference there is no option how to add images to this feed. Possible values are just 'photos' - images in Galleries, and 'picture' - FB page picture. No chance to get images which were added directly to post...

Any idea, how to add the 'images which were put directly into post' into my feed?

Thanks.

  • Check the `attachments` and `child_attachments` fields, and see if they contain what you’re after. https://developers.facebook.com/docs/graph-api/reference/v2.10/page/feed – CBroe Oct 24 '17 at 12:50
  • @CBroe: `(child-)attachments` are fields using for publishing, not reading. The link I read before is https://developers.facebook.com/docs/graph-api/reference/page, it should be the correct one for reading FB content and putting it to my website... I think :-) –  Oct 24 '17 at 13:06
  • Well then give an actual example of one of those posts you are interested in, please. – CBroe Oct 24 '17 at 13:35
  • @CBroe: for example https://facebook.com/10154097919877023. In my posts array above I have following: `create_time: xxx, message: 'A máme dostěhováno!', id: 10154097919877023`. There is no image url like https://scontent-frx5-1.xx.fbcdn.net/v/t1.0-9/15179191_10154097919877023_2418879268746255868_n.jpg?oh=a918790df02f891e208b3d7dcedc15a0&oe=5A83DAC7 –  Oct 24 '17 at 14:47
  • `picture`, `full_picture`, `attachments` ... take your pick: https://developers.facebook.com/tools/explorer?method=GET&path=43149742022_10154097919877023%3Ffields%3Dfull_picture%2Cpicture%2Cattachments%2Cchild_attachments&version=v2.10 – CBroe Oct 24 '17 at 15:05
  • @CBroe: Ah, I need to call more requests. In first loop get post IDs, ten call other requests using "pageID_postID" and ask for images... Cool, it should work. I tried to get all images to all posts (during last eg. week) using one query, it seems to be imposible. Your solution looks good. –  Oct 24 '17 at 15:09
  • Whether you do that for a single post, or a list of posts, does not make much of a difference - you can do the same thing using /page-id/feed, https://developers.facebook.com/tools/explorer?method=GET&path=43149742022%2Ffeed%3Ffields%3Dfull_picture%2Cpicture%2Cattachments%2Cchild_attachments&version=v2.10 – CBroe Oct 25 '17 at 07:46

0 Answers0