Testing your Facebook App in your Localhost

When creating an application that uses Facebook as an authentication method, a couple of things that you have to keep in mind so that you can test locally.

  1. Register your app at developers.facebook.com – Straight forward. This is where you’ll get your App ID, Secret ID and all them IDs.
  2. Change your app settings.
  3. This should reflect “Site URL – http://localhost.local/” and “Site Domain – localhost.local”

  4. Change your hosts file to reflect the change. This should point your 127.0.0.1 to localhost.local
    You can find the hosts file at C:\Windows\System32\drivers\etc\hosts. Make sure you run your notepad or any editing tool as administrator to be able to make the change.
  5. If you’re using IIS then you should take note of the default web site. It’s more straight forward if you’re running apache (I’m using XAMPP) as you just need to put it in the correct folder.
  6. If you didn’t get it right you’ll get an API Error Code: 191 API Error Description.
  7. When you start testing your app you should view the URL http://localhost.local/ instead of localhost only

Hope this helps and enjoy building your app!

Advertisement

9 Comments on “Testing your Facebook App in your Localhost”

  1. Clint says:

    Hi Eugene. Setting the Site URL to “http://localhost” works for me. In other words, after authenticating with FB the browser is correctly redirected back to http://localhost (where I have my app running locally). Is there a special reason that you recommend using the “custom” local host name “localhost.local” instead? I’m new to FB dev and want to make sure I’m not missing something… Thanks.

    • eugene1772 says:

      Hey Clint,
      No particular reason. On my PC localhost doesn’t work and I’m guessing it’s binded to another IP (probably IIS since I also have Visual Studio installed for ASP.NET development) so I made another entry in the hosts files to remedy this.

      Good luck on your FB development and share back what you have learned! 😀
      Eugene

  2. Clint says:

    Also, are there any risks to this? For example, if someone took my App ID and started using it with their own locally-hosted app, what damage could they do besides possibly exceeding my Graph API usage quota?

    • eugene1772 says:

      Never, ever share your App ID with anyone. None the less, if they got your App ID, you still have the secret ID so make sure you never share those two or else…

      • Clint says:

        Thanks for the replies. Mostly I was thinking about scenarios where you’re using JavaScript only (e.g., the client-side authentication method: http://goo.gl/sQ8gR). In that example, your App ID is publicly available through the JavaScript…

        Anyways, I also posted the question on the FB dev forum and got one response (http://goo.gl/fPb19); someone said it’s probably best to change your app settings to “Sandbox mode” when using localhost. Apparently this limits the auth logins to just the developer accounts associated with the App.

  3. Phuc says:

    hi Eugene,
    i have problem with facebook comment for wordpress this is a plugin you can find more here http://we8u.com/facebook-comments/#install
    i installed this plugin to my wordpress localhost but it did not show anything. i think this plugin can not contact with facebook because i call facebook via my localhost .
    any help will be appreciated.
    Thanks

    • eugene1772 says:

      Hi, I haven’t tested that plugin but I used other commenting plugins before like discus (which has the same functionality) I suggest you contact the developer of the plugin and get help from them.

  4. jonathan sanqui says:

    hi eugene,
    ifound your blog while running through tutorials on making a facebook app.
    im new to this thing and starting my way,
    im planning on developing a an app that updates a user’s status via the facebook app that i have created,
    so far, i have followed some tuts on downloading the facebook c# sdk, NuGet, btw im doing this desktop based using C#,
    i’ve made my FB app and FB page, and followed the tuts you have here on the testing on localhost, but so far i have not received any luck,
    i have no idea how to start coding my app im quite confused, any suggestion on where i should start? hope to hear from you

    • eugene1772 says:

      Hey Jonathan,

      I’m not really sure if my blog post is still relevant as it’s ages old. I’ll probably update it soon as it gets most of my traffic.

      Anyways, if you are using .NET, get NUGET package and download the facebook c# sdk. or download it here http://csharpsdk.org/ If you really want to learn how to use APIs, it might be a good way to not use the sdk and just do it on your own.

      Goodluck on your app and don’t get stuck studying the apis, but get down developing!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s