I\'ve got the Facebook user ID of the user who created a given page. Now I need to get the page ID to display like box in my website.
Different users have their own Face
These answers don't seem to work anymore since the graph now requires an access token for most if not all requests.
Here's a working solution that only requires as input the facebook page URL.
What this does is receives the facebook page as HTML and looks through(via regex) for a JSON entity_id
that has a numeric value. This value is the page's ID. This solution is surely not guaranteed to work forever since page content may change
/**
* @param string $facebookUrl
* @return null|string
*/
function get_facebook_id($facebookUrl)
{
$facebookId = null;
$fbResponse = @file_get_contents($facebookUrl);
if($fbResponse)
{
$matches = array();
if (preg_match('/"entity_id":"([0-9])+"/', $fbResponse, $matches))
{
$jsonObj = json_decode("{" . $matches[0] . "}");
if($jsonObj)
{
$facebookId = $jsonObj['entity_id'];
}
}
}
return $facebookId;
}