Paul
Paul

Reputation: 66

Facebook Application Tab URL

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.

Upvotes: 2

Views: 2805

Answers (4)

meeDamian
meeDamian

Reputation: 1164

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>

Upvotes: 0

David Li
David Li

Reputation: 11

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.

Upvotes: 0

Colm Doyle
Colm Doyle

Reputation: 3858

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.

Upvotes: 3

Tytus
Tytus

Reputation: 36

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

Upvotes: 2

Related Questions