I'm trying to make an automated post to a facebook page wall using Facebook SDK V5.
Actually I can post text, to the facebook page wall, but my image for some reason does not. I've followed instructions as this question Simple example to post to a Facebook fan page via PHP? but did not work(just posted text).
Then found this other oficial documentation https://developers.facebook.com/docs/php/howto/uploadphoto but it gives me an http 500 error, I think because of the CURLFile method, but my server has curl enabled and php 7 installed.
This is my actual code that posts text to facebook but image gets empty:
<?php
define('FACEBOOK_SDK_V4_SRC_DIR', 'Facebook/');
require_once('Facebook/autoload.php');
$appid = "xxxxxxxxxxxxxxxxxxxx";
$appsecret = "xxxxxxxxxxxxxxxxxxxx";
$pageAccessToken = "xxxxxxxxxxxxxxxxxxxx";
$pageFeed = "/me/feed";
$message="Obra: Cat Test";
//$pagURL = "https://www.madart.com.mx";
$img = "https://www.madart.com.mx/dev/cat.jpg";
$fb = new Facebook\Facebook([
'app_id' => $appid,
'app_secret' => $appsecret
]);
$linkData = [
'url' => 'https://www.madart.com.mx/dev/cat.jpg',
'message' => $message
];
try {
$response = $fb->post($pageFeed, $linkData, $pageAccessToken);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: '.$e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: '.$e->getMessage();
exit;
}
$graphNode = $response->getGraphNode();
?>