views:

3437

answers:

5

I'm making a simple iframe-based facebook app. I have the following code to size my iframe:

FB_RequireFeatures(["Connect"], function(){

FB.XdComm.Server.init('/xd_receiver.htm'); FB.CanvasClient.startTimerToSizeToContent(); FB.CanvasClient.syncUrl(); });

I want to add a link that will display a popup which will allow the user to post an app-defined image/link to the user's wall. To get things working initially, I tried just using the following code on a click event:

FB.Connect.streamPublish('');

However, nothing happens. I've tried adding:

FB.init(<?=API_KEY?>, '/xd_receiver.htm');

both inside the FB_RequireFeatures function, before it, after it... no luck. Nothing happens. No errors are thrown. Nothing. Any ideas?

A: 

Check that you have: (some from http://wiki.developers.facebook.com/index.php/Connect/Setting_Up_Your_Site#Referencing_Facebook_Connect_on_Your_Site)

  • Created xd_receiver.htm, and that it is in the root of your domain
  • Included the FeatureLoader.js.php at the top of the BODY of your document
  • Added the javascript in the question (e.g. FB_RequiresFeatures, etc) to the bottom of your document

An example of code that is currently running okay in my app:

<script type="text/javascript">
   window.onload = function() {
        FB_RequireFeatures(["XFBML", "Connect"], function() {
           FB.Facebook.init("...my api key...","xd_receiver.htm");
           FB.CanvasClient.syncUrl();
        });
   };
</script>

You can omit the "XFBML" from the FB_RequireFeatures call, and change the path to xd_receiver.htm too, and it should work okay.

In addition, double-check that the application's Connect URL (as set up via the Developer App in Facebook) points to a parent of the xd_receiver.htm file. So, if your app is hosted on http://www.mydomain.com, then looking at your code examples, your xd_receiver.htm will be at http://www.mydomain.com/xd_receiver.htm, and you'll want to have http://www.mydomain.com as the Connect URL.

If this still doesn't work, try installing Firebug (or similar tool) to have a look at the net traffic. When I was getting this to work, the Facebook Javascript API would fail silently, and it was only by inspecting the requests going back-and-forth that I spotted that Facebook didn't like my Connect URL.

In order to test that it's all working, I'd be tempted to use

FB.Connect.streamPublish();

rather that the line you posted, as it should pop-up a dialog, and is clearly given as a working example. I'm not sure what will happen if you just pass an empty string as an argument.

Finally, there are lots of IFrame-based Facebook apps out there - if you spot one that is doing something that you like, you can always have a look at their Javascript to find out how they achieved it. Or in other words, Facebook is full of example IFrame app code.

Cyphus
I'm including 'xd_receiver.htm' as needed. I DON'T have a Connect URL set because if I set it, every time I go to the app, it loads the actual URL in a new window instead of in Canvas within facebook. I have Firebug installed... I've tried doing console.log(FB.Connect.streamPublish()); and it prints out 'true'. I've tried both ('') and (), and I've seen both examples on the dev wiki... no go for either. I've looked at the responses in firebug, and it's not happy with my Connect URL (because one isn't set). However, if I set one, then going to the app takes me offsite.
Gary
You can't use the FB javascript client without setting a Connect URL. When the new window pops up, does streamPublish work? If so, all you need to do is fix the 'new window' problem and everything will be working as required.Looking back at what you've included in your question, I don't think we've got enough to work out why you're getting a new window. What browser are you using? Could you provide more of the HTML returned or do you have a URL we can visit to see the app running?
Cyphus
What I mean is that, if I set a Connect URL, going to the app causes Facebook to load the Connect URL (which is the same as my app's URL) instead of loading the data in the iframe within the Facebook Canvas.
Gary
When you say going to the app, I assume you mean going to http://apps.facebook.com/myapp?You should have a Canvas Callback URL which references your own server, e.g. http://mydomain.com/, which can also be your Connect URL. In fact, my app uses the same URL for both, which is probably pretty common.I'm intrigued as to how you are navigating to your app - are you going to http://apps.facebook.com/yourapp, or to the app itself (i.e. http://mydomain.com)?I could understand it not redirecting you to the Facebook-framed URL if you are requesting the app direct from your own servers.
Cyphus
A: 

You have to set your connect url in order to use the javascript libraries. Try setting your bookmark URL to http://apps.facebook.com/yourapp and see if that helps.

michael
A: 

@Cyphus

Yes, when I say 'going to the app' I mean going to the app's page on facebook (apps.facebook.com/myapp). Currently, I have my callback URL set to the canvas only. As soon as I tried using my callback URL for both the canvas AND the Connect URL, any time I tried to go to the app, instead of loading in an iframe within facebook, I was redirected to the actual callback URL itself. I don't request it directly from my server, since that somewhat defeats the purpose of having a facebook app.

Banderon
+1  A: 

Check out this page for complete instructions on setting up Stream publishing with iFrame apps using Connect:

http://thetechnicalexperience.blogspot.com/2010/02/how-to-use-fbconnectstreampublish.html

Michael
A: 

maybe you have need this :

FB.init("API CODE", "LINK DOCMENT ROOT/xd_receiver.htm");

link text

kaka