1

I am trying to figure out how to get the tab ID of the current tab of a Facebook Page the user is visiting.

I have made an app for installation on Facebook Pages, that I need to save settings for, per instance. I have figured out that you can get an array of tabs for the page the app is installed on, but I can't figure out how to get the tab ID for the actual tab you're on.

The point is for an admin to be able to save settings for each tab that they've added the app to, using a single backend. I'm not sure if you can have multiple instances of one app on the same page, but if not, we'd have 2-3 duplicate apps with the same backend in the iframe. Because of that, I need to be able to identify app installations as unique - the best way I can figure out is through using the page id and tab id, for the app.

How do I do that?

UPDATE: Found out that you can only have one instance per app on a page.

With that, I went with using this solution (with '/tabs/' to get the tab info):

try { 
  $tab = $facebook->api('/'.$fb_page_id.'/tabs/'.$fb_app_id);
  $fb_tab_link = $tab['data'][0]['link'];
} catch (FacebookApiException $e) {
  echo '<!-- '.htmlspecialchars(print_r($e, true)).' -->';
}

In the above code, $fb_tab_link or a combination of $fb_page_id and $fb_app_id can be used as unique identifier. I decided to use the concatenation $fb_page_id . '-' . $fb_app_id as the instance ID.

Calle
  • 1,690
  • 1
  • 17
  • 34
  • 2
    I'm not sure what you mean; your app is sent a 'page' parameter in the signed_request telling you what page the app is installed on, so you can use that to determine which content to show - can't you just use that to determine which page the app is installed on? – Igy Nov 29 '11 at 14:06
  • Yes, I wound up using the PAGE_ID/tabs/APP_ID api call, as a unique identifier, which also returns the link to the current tab. – Calle Nov 30 '11 at 15:40

4 Answers4

2

After some research, I found the call to get the tab information via the API.

try { 
  $tab = $facebook->api('/'.$fb_page_id.'/tabs/'.$fb_app_id);
  $fb_tab_link = $tab['data'][0]['link'];
} catch (FacebookApiException $e) {
  echo '<!-- '.htmlspecialchars(print_r($e, true)).' -->';
}

Apparently, the tab ID is the combination of Page ID and App ID, which means that you cannot install the same app to more than one tab on a page.

I hope this can be helpful to someone who needs to find the unique ID for a tab on a Facebook Page.

Calle
  • 1,690
  • 1
  • 17
  • 34
  • how can you get $fb_page_id, I tried it its working on first load of facebook page but when you redirect within your page tab app then we doesn't get signed_request parameters, So how we can manage this. – Priyank Feb 20 '14 at 17:30
1

In facebook api, when you want to change the tabname, you need to pass the tab id. see the example below.

To change your tab name using Javascript SDK.

your application tab_id will be app_[AppId].

FB.api([PageId]/tabs/[tab_id]', 'post', 
{access_token: [page access token], custom_name:[custom tab name]},
function(response){
if(respose == true)
console.info("Successfully done");
}
);
sushilprj
  • 2,203
  • 1
  • 14
  • 19
  • This was off topic - the issue is not to change the name of a tab, but to retrieve an (unchangeable) ID for each installed instance of the app in a tab. – Calle Dec 14 '11 at 13:58
  • Right Calle, Actually I have posted this because it is using tab id. I am also changing the text of my post. – sushilprj Dec 16 '11 at 05:18
0

Ok Calle thanks for the confirmation! I was trying to figure out this too... and it makes sense... That's why when you create a tab programmatically for a page the only parameters are app_id & access_token. If you try to create an app tab twice on the same page you'll get "true" which in my opinion means that you overwrite last tab you have created.

Beto Aveiga
  • 3,466
  • 4
  • 27
  • 39
0

Facebook adds a signed_request parameter to the request URL of your app. You can decode this parameter to obtain the page ID, among other useful information:

http://developers.facebook.com/docs/authentication/signed_request/

karlgold
  • 7,970
  • 2
  • 29
  • 22
  • Yes, the Facebook API for PHP handles the signed_request, so that's called before the `$tab = $facebook->api('/'.$fb_page_id.'/tabs/'.$fb_app_id);` – Calle Feb 10 '12 at 11:49