Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Facebook application on localhost

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?

like image 227
enthusiastic Avatar asked Feb 27 '11 11:02

enthusiastic


People also ask

How do I stop enforce https on Facebook Developer?

This setting is in the Products > Facebook Login > Settings section of the App Dashboard. Disable this setting if you are not building a custom web login flow or using the Facebook Login SDK on the web. Enforce HTTPS.

How do I add Facebook login to my website?

View App Review Requests From there, scroll through the list of options and click Request for any permissions you'd like to add. You'll need to fill out a form that confirms your Facebook Login button is live and can be tested. Also describe how people use your site and how you'll use the requested permission.


2 Answers

I wrote a tutorial about this a while ago.

The most important point is the "Site URL":

Site URL: http://localhost/app_name/

Where the folder structure is something like:

app_name ¦   index.php ¦ +---canvas ¦   ¦   index.php ¦   ¦ ¦   +---css ¦           main.css ¦           reset.css ¦ +---src         facebook.php         fb_ca_chain_bundle.crt 

EDIT:
Kavya: how does the FB server recognize my localhost even without an IP or port??

I don't think this has anything to do with Facebook, I guess since the iframe src parameter is loaded from client-side it'll treat your local URL as if you put it directly on your browser.

For example have a file on your online server with content (e.g. online.php):

<iframe src="http://localhost/test.php" width="100%" height="100%">     <p>Not supported!</p> </iframe> 

And on your localhost root directory, have the file test.php:

<?php echo "Hello from Localhost!"; ?> 

Now visit http://your_domain.com/online.php you will see your localhost file's content!

This is why realtime subscriptions and deauthorize callbacks (just to mention) won't work with localhost URLs! because Facebook will ping (send http requests) to these URLs but obviously Facebook server won't translate those URLs to yours!

like image 97
ifaour Avatar answered Oct 12 '22 02:10

ifaour


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.

like image 31
user3531155 Avatar answered Oct 12 '22 04:10

user3531155