I'm trying to post one photo with some text to my Facebook Page, but right now I get this error message:
Template data must be a JSON-encoded dictionary, of the form {'key-1': 'value-1', 'key-2': 'value-2', ...}
This is my code:
<?php
session_start();
require_once __DIR__ . '/Facebook/autoload.php';
$filename = __DIR__ . '/static/images/test.png';
$acces_token = "my-valid-never-expiring-page-acces-token";
$pageid = "987654321987654321";
echo "<p>START</ps>";
$fb = new Facebook\Facebook([
'app_id' => '123456789',
'app_secret' => 'appsecret123456789abc',
'default_graph_version' => 'v2.8',
]);
try {
$response = $fb->post(
'/'.$pageid.'/feed',
array(
"message" => "test test",
"source" => new CURLFile($filename, 'image/png')
),
$acces_token
);
}catch(Facebook\Exceptions\FacebookSDKException $e) {
echo $e->getMessage();
exit;
}
catch(Facebook\Exceptions\FacebookAuthenticationException $e) {
echo $e->getMessage();
exit;
}
?>
Sadly I don't see any errors on the server in the error.log, so it must be something within the Facebook API :(
What am I doing wrong? Thank you!
EDIT:
After changing '/'.$pageid.'/feed' to '/'.$pageid.'/photos' the problem is gone, but I have another one:
(#324) Requires upload file
I found the solution myself:
$response = $fb->post(
'/'.$pageid.'/photos',
array(
"message" => "test test",
"source" => $fb->fileToUpload($filename)
),
$tokens[$i]
);