2

I have a facebook application that can be added to fan pages as a tab. The application requires that users are authenticated in order to use it. This can be accomplished by using requirelogin=1 in a link which is visible only to users who have NOT added the application. This part works fine.

However, after the user has given my application permission from the dhtml pop up that requirelogin opens, I want the tab to reload. In order to do that, I need the full URL to be included in the link as follows:

<a href="http://www.facebook.com/pages/PAGE_NAME/PAGE_ID?v=app_APP_ID" requirelogin=1>Authorize</a>

I cannot figure out how to get the full url or, at least, the PAGE_NAME to build this url dynamically. Seems like the app should be able to know where it is without any special permissions.

Paul
  • 66
  • 1
  • 5

4 Answers4

3

When your Tab is loaded, the API passes you a Signed Request that contains, amongst other things, a page array contain id, liked & admin. You can use that to dynamically pull the page id that's currently calling your code.

Colm Doyle
  • 3,598
  • 1
  • 20
  • 22
  • page_id **IS NOT** a tab id, so you can reload only to page stream, and it's not reloading per se if you change address during the process ;P – meeDamian May 08 '12 at 10:07
  • Have a look at the URL format Tytus provided -- the app id is static, and the page id can be extracted from the signed_request. Just correct the typo in his link (& instead of #). i.e. http://www.facebook.com/profile.php?id=PAGE_ID&v=app_APP_ID – 1in9ui5t Sep 18 '13 at 03:29
2

If you have the PAGE ID and APP ID, this is what you do:

http://www.facebook.com/profile.php?id=PAGE_ID#v=app_APP_ID

For example:

http://www.facebook.com/profile.php?id=282955631557#v=app_278523304881
Tytus
  • 36
  • 4
  • ... yes but that requires have the page id (hard coded) in advance... it is not a dynamic solution. – Paul Apr 12 '10 at 10:25
0

In the new scheme, the # no long works. One needs to use

http://www.facebook.com/profile.php?id=PAGE_ID#v=app_APP_ID

To carry parameters to the app, it has to be in a parameter called 'app_data'

http://www.facebook.com/profile.php?id=PAGE_ID#v=app_APP_ID&app_data="..."

To carry multiple parameters, the best strategy is to encode app_data in Json.

David Li
  • 11
  • 1
0

All of the above answers will not work (redirect you only to page stream) or are deprecated now. The best solution thou is using JS:

// called when like button, box, etc is rendered
FB.Event.subscribe("xfbml.render", function() { 

    // assigns click to that thing
    FB.Event.subscribe("edge.create", function(response) { 

        window.location.reload(); // reload frame only

    });
});

You'll also have to load and init facebook JS SDK. If you don't know how to do it, use this:

<script>
    document.onload = function(){

        (function(d){
            var js,id='facebook-jssdk';
            if(d.getElementById(id)){return;}
            js=d.createElement('script');
            js.id=id;js.async=true;js.src="//connect.facebook.net/pl_PL/all.js";
            d.getElementsByTagName('head')[0].appendChild(js);
        }(document));

        window.fbAsyncInit = function(){
            FB.init({
                appId  : <PASTE_YOUR_APP_ID_HERE>,
                status : true, // check login status
                cookie : true, // enable cookies to allow the server to access the session
                xfbml  : true  // parse XFBML
            });
            FB.Event.subscribe("xfbml.render", function() {
                FB.Event.subscribe("edge.create", function(response) {
                    window.location.reload();
                });
            });
        }
    }
</script>
meeDamian
  • 1,143
  • 2
  • 11
  • 24