I am currently working on an app that connects high school students with nonprofits to help manage their social media pages and gain community service hours.
We give each student a social impact score calculated by the amount of likes, comments, shares that are garnered by their posts for the foundations. We are trying to create a server that pulls data from these Facebook pages with a never-expiring Page Access Token. Does this require a login script if we try to retrieve data on an ongoing basis? Also, our code below keeps showing an error.
What is wrong with it?
<?php
// Defining FB SDK with absolute paths
define('FACEBOOK_SDK_V4_SRC_DIR', 'http://www.website.com/src/Facebook/');
require 'http://www.website.com/src/Facebook/autoload.php';
use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\GraphUser;
use Facebook\FacebookRequestException;
FacebookSession::setDefaultApplication(‘App ID’,’App Secret’);
$session = new FacebookSession(‘Never expiring page access token’);
try {
$data = (new FacebookRequest(
$session, 'GET', '/1503911716546178/posts'
))->execute()->getGraphObject()->getPropertyAsArray("data");
foreach ($data as $post){
$postId = $post->getProperty('id');
$postMessage = $post->getProperty('message');
print "$postId - $postMessage <br />";
}
} catch (FacebookRequestException $e) {
// The Graph API returned an error
} catch (\Exception $e) {
// Some other error occurred
}
?>