For an application I am developing, we allow users to add a link to their Facebook Page (strictly page, not Profile, not Group, only a Page).
I cannot find anything
I needed something that checked to see if it was a valid Page or Group. My user submits a text field which comes via $_POST
as $_POST['mu_facebook']
if(class_exists('Facebook')){
$facebook = new Facebook(array(
'appId' => 'yourapplicationID',
'secret' => 'yoursecretcode',
'cookie' => true,
));
//break up the saved URL to see what we're dealing with
$parts = explode('/', $_POST['mu_facebook']);
if($key = array_search('groups', $parts))
$query = $parts[$key+1]; //if this is a group URL, the ID will be in the next key after /group/
else
$query = $_POST['mu_facebook'];
try {
$fb_data = $facebook->api($query);
} catch (FacebookApiException $e){
//insert your own error here - Facebook did not recognize this object (group id failures will happen here)
}
//If FB doesn't recognize the URL, the API simply shows the requested URL as the id or returns an object wth type = 'website' (Page URL failures will happen here)
if($fb_data["id"] && $fb_data["id"] !== $_POST['mu_facebook'] && $fb_data["type"] !== "website"){
//We have a valid URL
update_as_site_option('mu_facebook');
} else {
//insert your own error here - Facebook did not recognize this object
}
}