You can provide App to Fan Page Tab using URL, but you must check below options to get App (Page Tab) Added Page ID?
https://www.facebook.com/dialog/pagetab?app_id=YOUR_APP_ID&next=YOUR_URL
After successful authorization users will redirect to your Site URL with pageID
http://www.domain.com/?tabs_added[pageID]=1#_=_
Integrating with Facebook APIs
When a user selects Page Tab and authorize your application, you receive the signed_request parameter with one additional parameter, page.
JSON object
– id (the page id of the current page)
– admin (if the user is a admin of the page)
– liked (if the user has liked the page).
Option 1: Canvas Page
$signedRequest = $facebook->getSignedRequest();
Option 2: App Domain / Site URL
if(array_key_exists(‘tabs_added’, $_REQUEST)) {
$id = array_keys($_REQUEST[‘tabs_added’]);
$pageId = $id[0];
echo $pageId;
}
Option 3: Page Tab URL
if (!empty($_REQUEST[‘signed_request’])) {
list($encodedSig, $payload) = explode(‘.’, $_REQUEST[‘signed_request’], 2);
$requestData = json_decode(base64_decode(strtr($payload, ‘-_’, ‘+/’)), true);
if (!empty($requestData[‘page’]) && isset($requestData[‘page’][‘id’])) {
$pageId = $requestData[‘page’][‘id’];
echo $pageId;
}
}
Option 4: App Domain / Site URL
<div id='fb-root'></div> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script src='http://connect.facebook.net/en_US/all.js'></script> <p><a onclick='addToPage(); return false;'>Add to Page</a></p> <p id='msg'></p> <script> FB.init({appId: "APP_ID", status: true, cookie: true}); function addToPage() { // calling the API ... FB.ui( { method: 'pagetab' }, function(response) { if (response != null && response.tabs_added != null) { $.each(response.tabs_added, function(pageid) { alert(pageid); }); } } ); } </script>
Your app will also receive string parameter app_data as part of signed_request if app_data parameter was set in the original query string in the URL your tab is loaded on.
“https://www.facebook.com/YourPage?v=app_APP_ID&app_data=STRING”