I am planning to connect to Facebook chat from my localhost. I will need to get the session key from Facebook. When I give the site URL as localhost:8080
or ip-address:8080
it does not work.
I read about setting up two apps with 2 different API keys one runs on dev m/c and other on localhost but I did not quite get it.
Can anyone explain how to run a Facebook app on localhost?
if you use localhost:
in Facebook-->Settings-->Basic, in field "App Domains" write "localhost", then click to "+Add Platform" choose "Web Site",
it will create two fields "Mobile Site URL" and "Site URL", in "Site URL" write again "localhost".
works for me.
A trick:
Use MAMPPRO and create: server name: the EXACT adress of you website (eg: helloworld.com) to your site on your disk
On Facebook: So you can keep your original Site URL as well (eg: helloworld.com)
Now you understand that when you type your website on the adress bar you are in local! ..and when you want to be online, just inactive the server on MAMP PRO..
:)
Ok I'm not sure what's up with these answers but I'll let you know what worked for me as advised by a senior dev at my work. I'm working in Ruby on Rails and using Facebook's JavaScript code to get access tokens.
Problem: To do authentication, Facebook is taking the url from your address bar and comparing that with what they have on file. They don't allow you to use
localhost:3000
for whatever reason. However, you can use a completely made-up domain name likeyoursite.dev
by running a local server and pointingyoursite.dev
to127.0.0.1:3000
or wherever your localhost was pointing to.Step 1: Install or update Nginx
$ brew install nginx
(install) or$ brew upgrade nginx
(update)Step 2: Open up your nginx config file
/usr/local/etc/nginx/nginx.conf
(usually here)/opt/boxen/config/nginx/nginx.conf
(if you use Boxen)Step 3 Add this bit of code into your
http {}
blockReplace
proxy_pass
with wherever you want to pointyoursite.dev
to. In my case it was replacing localhost:3000 or the equivalent127.0.0.1:3000
Step 4: Edit your hosts file, in
/etc/hosts
on Mac to includeThis file directs domains to localhost. Nginx listens in on localhost and redirects if it matches a rule.
Step 5: Every time you use your dev environment going forward, you use the
yoursite.dev
in the address bar instead oflocalhost:3000
so Facebook logs you in correctly.Forward is a great tool for helping with development of facebook apps locally, it supports SSL so the cert thing isn't a problem.
https://forwardhq.com/in-use/facebook
DISCLAIMER: I'm one of the devs
In your app's basic settings (https://developers.facebook.com/apps) under Settings->Basic->Select how your app integrates with Facebook...
Use "Site URL:" and "Mobile Site URL:" to hold your production and development URLs. Both sites will be allowed to authenticate. I'm just using Facebook for authentication so I don't need any of the mobile site redirection features. I usually change the "Mobile Site URL:" to my "localhost:12345" site while I'm testing the authentication, and then set it back to normal when I'm done.
So I got this to work today. My URL is
http://localhost:8888
. The domain I gave facebook is localhost. I thought that it was not working because I was trying to pull data using theFB.api
method. I kept on getting an "undefined" name and an image without a source, so definitely didn't have access to the Graph.Later I realized that my problem was really that I was only passing a first argument of
/me
toFB.api
, and I didn't have a token. So you'll need to use theFB.getLoginStatus
function to get a token, which should be added to the/me
argument.