Thursday, February 26, 2009

Testing Facebook Connect Locally

I've been experimenting with integrating features from the social networking site Facebook into tinyvid. To do this I'm using the 'Facebook Connect' API.

When you register a Facebook application you need to provide URL's to your application's site so Facebook knows where to send the user on redirects from logging in, and handle messaging between Facebook and your application.

To handle the case of being able to develop and test on a local server, and deploying to the live server. This is the 'Callback URL' setting in the application setup. This can contain an IP address and port number so for testing locally you can set it to a local IP address. For example, http://127.0.0.1:9000.

Facebook doesn't try to contact this directly, it redirects the browser to it, so this works fine when testing the application locally. You can create two applications, one with the testing Callback URL, and one with the production one, and make this a parameter in your application.

Another option that worked for me was to set the Callback URL to the production domain (in this case, tinyvid.tv) and locally set my hosts file so that tinyvid.tv resolved to localhost. The web server needs to run in port 80 locally for this to work.

Categories:

Labels:

5 Comments:

Blogger Barış Şeker said...

Great suggestions, thanks

8:43 AM  
Blogger alex said...

Thanks for posting this.

This only works if you have Apache setup on your local machine though, right?

Or can you open up a file and browse to it locally (e.g. file:///)?

11:00 AM  
Blogger Chris Double said...

Yes, you need a webserver like apache set up on the local machine. I don't know of a way to use a local file unfortunately.

12:34 PM  
Blogger ceme said...

This works in kind of a crippled way. Some FBML tags are not processing correctly(e.g. no thumbs are rendered).
Quote from the FB forum:
"FBML is parsed by Facebook's server when it loads your page before sending it to the browser, not by your browser with some magic extensions. For this reason, you can't use FBML when using localhost to develop your app, as it has to go through FB's servers." via @dosxuk http://bit.ly/8ktnS0
and some of the JS API calls are not working(e.g. FB.Connect.blah()) so I can't evoke modal dialogs like posting status or extending permissions. I am pointing to a local Tomcat server with a port # (i.e. Connect URL), so my FB dev app is set up with a specific ip:port#/path. I can then do some processing like reload my original calling URL after FB does the authorization and browser redirect. It is really not a great representation of how it will work LIVE, but at least I get partial functionality. Thanks for the tip though, it was pretty helpful.

1:53 PM  
Blogger Peter Charron said...

There's a lot of chatter on the Web about testing on localhost, all very different.

I'm building a Grails app and trying to test on my mac.I'm not sure how to configure my sandbox app in facebook, where in my grails app to put the xd_receiver.htm file and what should be in my Fbinit statement.. HELP!

The original post says "callback URL" should be set but user CEME says "connect URL" . Which is it?

6:36 PM  

Post a Comment

<< Home