Search code examples
phpfacebookfacebook-graph-apifacebook-php-sdk

Create custom open graph


Here's the scenario, when you post a link to Facebook, the scraper makes an open graph story based on og tags. However, I woudl like to know if it's possible to change the image retrieved by the scraper with one loaded by the user.

Imagine it like this, I want to post a link but the referenced site has no image, I'd like to modify the story so that its image is one I upload manually. Is that possible?


Solution

  • I found the answer in the API as suggested by CBroe. To clarify, I'm posting to a page, not to a profile, so I used the parameter link to, obviously, specify the link I was sharing. I also used the parameter picture to replace the thumbnail the scraper fetches with one I wanted.

    This picture is a url, not an uploaded file, if someone is wondering.

    So, the final array that will be sent to Facebook's API looks like this:

    $data = ['message' => 'your message', 'link' => 'your-link.com', 'picture' => 'url/to/image.jpg'];
    

    As I said, this will post a link to a page and replace the thumbnail fetched from Facebook's scraper with the image specified in the picture parameter.

    Hope this helps anyone else with the same question :)