I'm Leandro Lovisolo, a computer science student at University of Buenos Aires, Argentina.
You can read more about me here.

Facebook apps and /etc/hosts

Are you developing Facebook apps? Does this picture look familiar to you?

Facebook popup error

This happens when you’re developing a Facebook application locally using the http://localhost:8080 URL to test your app (or whatever port it’s listening to) and you try to log in using your Facebook account.

The reason for this is that the JavaScript SDK expects your app to be running from the domain you’ve entered in your app’s settings page.

I’ll transcribe the error here so this article can be found from search engines more easily:

API Error Code: 191
API Error Description: The specified URL is not owned by the application.
Error Message: redirect_uri is not owned by the application.

The usual workaround

Assuming that your application’s domain is mywebapp.com, your first attempt at circumventing this problem would probably be to add the following line to your /etc/hosts file and comment it out when you’re done testing your app locally:

127.0.0.1	mywebapp.com

The main problem with this is that you end up editing the hosts file all the time, which can be pretty inconvenient.

A better approach

A less painful way to fix this is to define an alias just for a subdomain, e.g. local.mywebapp.com, and use that alias instead of localhost when you’re developing locally:

127.0.0.1	local.mywebapp.com

This way, you can test your app locally using http://local.mywebapp.com:8080 and forget about editing the hosts file ever again.

This works because the JavaScript SDK sees that all your URLs belong to the application domain.

Fork me on GitHub