Post a facebook page/feed with image using graph api

Viewed 3573

I'm struggling to post a facebook page/feed with a image. I'm following all the documentation but, damm :(, it's not working

https://developers.facebook.com/docs/graph-api/reference/v2.10/page/feed#publish

using the object_attachment to pass and upload photo id.

I've tried with an already uploaded image and a new upload but Nothing appears to work

If i run this, all works as expected but the image does not work

$args = array( 'access_token'  => $pag_access_token,
               'message' => $description,
               'object_attachment' => $photoID,
               'link' => $link);
$status = $facebook->api("/$facebookUsername/feed", 'post', $args);

Note: $photoID is a valid facebook photo.

Result: Page feed after run the above code

Any thoughts??

Update: SOLUTION

Thanks to @Norbert insights heres how we can accomplish that:

Using the Graph api we need to pass the access_token, the link (important) and a description (optional)

  1. On the api endpoint, i was just sharing the message and the link to my frontend page.

    $args = array( 'access_token' => $pag_access_token, 'message' => "option text", 'link' => $options['link']);

    $status = $facebook->api("/$facebookpage/feed", 'post', $args);
    

With the above code you will be able to share to facebook feed your message, but without the title of your post and the image.

To do that you will need to add the following metadata into your destination page ($link that was shared)

2.

<meta property="og:url" content="YOUR URL">
<meta property="og:type" content="website">
<meta property="og:title" content="URL TITLE">
<meta property="og:description" content="SMALL DESCRIPTION">
<meta property="og:image" content="http://IMAGE SERVED WITH HTTP">
<meta property="og:image:secure_url" content="https://IMAGE SERVED AS HTTPD">

if the url you want to share is served over https you must also include the og:image:secure_url They need to be served under the same protocol.

Hope this help everyone with the same problem.

Regards

0 Answers
Related