Php – facebook connect using FB.Connect.showFeedDialog without fb:login-button

facebookPHP

I have a facebook application set as a iframe and i'm trying to use FB.Connect.showFeedDialog to publish stories to a users feed. I'm working from this example http://papermashup.com/using-facebook-connect/ which doesn't work until you login using the fb:login-button.

I've been attempting to modify the code for several days and I was wondering if it's even possible to do without this login button if its a Facebook Iframe applicaiton.

Any help and pointers much appreciated.

Best Answer

It's definitely possible without a fb:login-button. In fact, if you're building an iframe app, then you probably don't need an fb:login-button at all. All you need is to load the Facebook Connect libraries, and then make the initialize call, like this (using your own API key of course):

<script src="http://static.ak.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
<script type="text/javascript">
    FB.init("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "/xd_receiver.htm");
    window.addEvent('domready',function(){
        FB_RequireFeatures(["CanvasUtil"], function(){
            FB.XdComm.Server.init("/xd_receiver.htm");
        });
    });
</script>

Note that I've got a bit of MooTools in there to make sure the RequireFeatures call happens after the DOM is ready. You can stick to the examples in the initializing docs if you want.

Anyway, once you've loaded and initialized the FB Connect libraries, you should have full access to the API methods that the JS library provides, and you can simply do this:

var user_message_prompt = "Write something here!";
var user_message = {value: "Default message"};
if (FB.Connect) {
    FB.Connect.showFeedDialog(templateBundle, templateData, null,null,null,FB.RequireConnect.require,null,user_message_prompt,user_message);
}
Related Topic