I am attempting to retrieve the number of fans for my Page via the PHP SDK. Here is all of my code so far.
$fbSession = \Facebook\FacebookSession::newAppSession(self::APP_ID, self::APP_SECRET);
$fbLikesResponse = null;
try {
$fbLikesRequest = new \Facebook\FacebookRequest($fbSession, 'GET', '/{myRealPageIDGoesHere}/insights/page_fans');
$fbLikesResponse = $fbLikesRequest->execute()->getGraphObject()->asArray();
} catch (\Facebook\FacebookRequestException $ex) {
$resp = new \stdClass();
$resp->error = $ex;
return $resp;
} catch (\Exception $ex) {
echo $ex->getMessage();
}
//Add items to response and to store
var_dump($fbLikesResponse);
I never get authentication/authorizaiton errors, but the data response value is always just 0. I can see on the Facebook page itself that there are more than 0 likes.
I really don't want to have to resort to screen-scraping to obtain how many likes my Facebook page has. Any idea why I only get 0s?
Clarification- this is for a server-side call for an analytics engine. No user authentication is involved, so I'm trying to figure out how to get hit the {node}/insights/page_fans endpoint without faking some sort of user login.