开发者

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/PAG开发者_StackOverflow社区E_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.


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.


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


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.


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜