开发者

how can i use localhost while developing facebook graph website?

i want to use localhost for developing website facebook application usin开发者_StackOverflow社区g 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.


Add "localhost" to the "App Domain" setting of your app on Facebook. Also, if you are doing something like redirecting "MyApp.test" to 127.0.0.1 on your local server, you can also add "MyApp.test" to the "App Domain" and it will work.

I just tried this after looking for a solution to this problem. It is a very simple solution.


Check the following Basic Settings in your app's Facebook configuration:

  • Namespace has been set
  • App Domain includes "localhost"
  • Canvas URL and Secure Canvas URL both have a domain of "localhost" in their URL

If you are getting an "application name" error when you save the app's configuration settings are you sure the name of the app is valid and not already taken? We use localhost (with ASP.Net, IISExpress, and very high port numbers) all the time with four or five different applications with multiple users on different machines and never need to do any of the extra steps some people have described in their answers.

EDIT: after re-reading other answers I guess some devs are developing on the same Facebook app as they use for production, so they need to map their machine to the production domain? We don't do that, we have two "apps". One is for testing with the localhost configuration and another for production. We have a component that determines at runtime which environment it's in and constructs all the necessary URLs such as OAuth redirects with App IDs and App Secrets so we're always running the same code, just different configuration deployed on different servers.


Are you sure that problem is related to DNS name and/or port of your web server? If yes you can use your local IIS instead of webdev server, configure a website yourdomain.com and add an entry to the hosts saying 127.0.0.1 yourdomain.com


If I understand correctly of what you're trying to do and the application settings are on Facebook's website, Facebook will not be able to connect to your computer with 'localhost'. Get the IP address of your computer and type that into the application settings page.

To find your IP: http://whatismyipaddress.com/


You have to create a ssh tunnel FROM develop server TO your localhost computer. Each request to dev server will be processed by your computer and send back.


You cannot add top level domains on Facebook setting FYI

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜