I'm working on publishing posts from our FB page on our website. Each new post and photos we added into our FB page I need to show in our website too.
I have this code, but don't working as I need.
require 'php-graph-sdk-5.x/src/Facebook/autoload.php';
$fb = new Facebook\Facebook([
'app_id' => '...',
'app_secret' => '{app-secret}', // don't know where to find app_secret for my page, I've found that just for apps, not pages
'default_graph_version' => 'v2.10'
]);
$access_token = '...'; // generated in developers, but with just for 12 hours, than this token is expired... :-(
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get('me?fields=id,name,feed,data', $access_token);
} 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();
foreach ($graphNode as $node) {
foreach ($node as $items) {
print_r($items);
// when access token was valid, I got posts from out FB page. But with no images, didn't find how to get add images to this feed...
}
}
So, my questions are:
where I can find app-secret for FB page? I'm not able to connect to my FB page without that, I think
how to generate permanent access token, or if it's not possible, how to make i other way?
how to add images (new, shared, etc.) to my feed?
Thanks.