TJ Sherrill
TJ Sherrill

Reputation: 2645

How do I pass a query string to a Facebook tab app url based on the user who added the tab to their page

I have a pretty straight forward page tab app that can be added to anyones FB page. I am providing a button on my site to help users add the app to their FB page.

I want to update the iframe page tab url (and secure url) to include a query string. This will allow the content of the iframe to be custom for each user that adds the app to their page.

A basic use case is that User 1 clicks the button and the app gets added to their page. The content of the iframe is specific to user 1. User 2 does the same but the content of his tab is specific to user 2. I can handle the query string stuff on my site so that it responds correctly but I am not sure how to have the Tab url add the query string parameter from the Add App to Facebook button.

the current add app to facebook code I am using:

<div id='fb-root'></div>
<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: "252314034891861", 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>

thanks for your help!

EDITED TO ADD MORE INFO

After talking this over with another dev, I wanted to make sure I am clear. Is User1 adds the tab to their page, then no matter who views the tab, the content will always be the contextual to User1. If User2 adds this tab to their page, then no matter who views the tab, the content will be contextual to User2. The content of the tab is specific to the user who added the tab to their page.

Upvotes: 3

Views: 2754

Answers (1)

Igy
Igy

Reputation: 43816

You should make the content change based on the Page ID instead of the User ID of the Page Admin which added it. Short version: this is because you can't reliably pass the user ID of the page admin in loads of the app (or any other information really, as users can manually access the tab)

However, the page ID is passed with every request to your app via the page property of the signed_request along with some other parameters including the current user id (if they've authorised your app) and whether they've liked the page or are an admin of the page (regardless of their authorisation status)

An app can't be installed onto a page more than once, so the App ID / Page ID will be unique for your purposes

The only other parameter you can pass through to a page tab app to customise the display is the app_data parameter which will be sent in the page property of the signed_request, but this only applies to links which contain that parameter: users clicking on the page tab directly won't have that parameter passed through and would get the uncustomised content

See the Page Tab tutorial in the getting started section of the Docs for more information

Upvotes: 3

Related Questions