i want to use localhost for developing website facebook application using the graph api. i working in asp.net c#
in the previous api of facebook i was abe to write the http://localhost:4300/ in the connect url at the application settings.
now it dosent work. it keeps telling me An error occurred with application name. Please try again later.
anybody suggestions ?
** if i upload the website, and use the website coonect url, it is working.
Facebook doesn't care what actual IP address your server is located at - but it will check that the domain name of the referring page is the same as the domain you registered with facebook. The trick to getting it to work during development is to find a way to use your domain name even when you're just working on your local machine for development.
If you have full control of your DNS records you could add a host record (eg 'test.yourdomain.com' ) which either points at the real IP address of your development machine (if it's a static ip), or simply to 127.0.0.1
If you don't have access to your DNS then the easiest way to get around this during development is to simply add an entry to your computer's hosts file ('/etc/hosts' on OSX and most other unix machines) pointing the domain you registered at facebook to your local host machine. so you'd add a line like this :
127.0.0.0 test.yourdomain.com
to the end of your hosts file. That means that if you now enter test.yourdomain.com in your web browser it will resolve to your local machine.
Now - in the "web site" section of your application setup in Facebook make sure you have added your domain name to the "site domain" section of the setting - this will mean that facebook will accept requests coming from any subdomain of your domain - in other words it will accept requests from both "www.yourdomain.com" (your production server) and "test.yourdomain.com" (your local development machine).
Now you should just be able to develop on your local machine using the "test.yourdomain.com" url in your browser rather than 'localhost' and everything should work.
OH - one more thing - the facebook redirect uri will also need to have a port number if your development server isn't running on port 80, but it includes this port number when matching the domain url (frankly i consider this a bug in the facebook APIs). This means that if your development server is (for instance) running on port 8080 then you'll need to add ':8080' to the end of the hostname in the redirect URI, but if your productions server is running on port 80 then you shouldn't put ":80" in the redirect uri because otherwise it'll only work when people have explicitly included the port number in the URL they used to look at your page (unlikely in a production server). What this all means in practice is that you just have to have a conditional so that when generating the facebook authentication URL you only include the port number if it's not port 80.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With