English 中文(简体)
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.

问题回答

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>




相关问题
Facebook Connect login dialog not working

I am using Facebook Connect for iPhone and following the official instructions. I use the following code to display the login dialog: FBLoginDialog* dialog = [[[FBLoginDialog alloc] initWithSession:...

Facebook App Profile Tab is Empty ... No Content Displayed?

I can view my application via the http://apps.facebook.com/myapplication/ link and the content shows up correctly. I also added the application as a tab to a facebook page. However, when viewing the ...

Facebook Platform error: "Object cannot be liked"

I m working on a Facebook Application that generates wall posts. In testing these posts, I ve discovered that the Facebook Platform action of "liking" a post is failing. The specific error message ...

how to call showPermissionsDialog() in php (facebook api)?

I was reading over the documentation yet I could not figure out how to call Facebook.showPermissionsDialog() in php include_once ./facebook-platform/php/facebook.php ; $facebook = new Facebook(my ...

Facebook connect

If I plug in the facebook connect into my website, How can I prevent double signups? Lets say I have a user that s already signed up to my site but he clicked the connect with facebook, is there a ...

热门标签