Facebook javascript connects to localhost domain

I am trying to create a facebook connection using javascript that gives a follwing error:

This URL is not allowed by application configuration. One or more of the specified URLs is not allowed by the application settings. It must match the website URL or canvas URL, or the domain must be a subdomain of one of the application domains.

Is this because I'm using a Localhost server for testing? Do I need to buy a domain to check this or what? Or I need to make changes to the following code:

my code is:

<?php // // uses the PHP SDK. Download from https://github.com/facebook/php-sdk include("facebook-php-sdk/src/facebook.php"); // // from the facebook app page define('YOUR_APP_ID', '321849981247524'); define('YOUR_APP_SECRET', '49fd00ce6237aff0af08fd8ca25dbc92'); // // new facebook object to interact with facebook $facebook = new Facebook(array( 'appId' => YOUR_APP_ID, 'secret' => YOUR_APP_SECRET, )); // // if user is logged in on facebook and already gave permissions // to your app, get his data: $userId = $facebook->getUser(); ?> <html> <head> <style>body { text-align:center; font-size: 40px }</style> </head> <body> <?php if ($userId) { // // already logged? show some data $userInfo = $facebook->api('/' + $userId); echo "<p>YOU ARE: <strong>". $userInfo['name'] ."</strong><br/>"; echo "Your birth date is: ".$userInfo['birthday']."</p>"; } else { // // use javaascript api to open dialogue and perform // the facebook connect process by inserting the fb:login-button ?> <div id="fb-root"></div> <fb:login-button scope='email,user_birthday'></fb:login-button> <?php } ?> <script> window.fbAsyncInit = function() { FB.init({ appId : <?=YOUR_APP_ID?>, //When I gives app ID "321849981247524" or my own created it gives error that it not valid status : true, cookie : true, xfbml : true, oauth : true, }); FB.Event.subscribe('auth.login', function(response) { // ------------------------------------------------------ // This is the callback if everything is ok window.location.reload(); }); }; (function(d){ var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} js = d.createElement('script'); js.id = id; js.async = true; js.src = "//connect.facebook.net/en_US/all.js"; d.getElementsByTagName('head')[0].appendChild(js); }(document)); </script> </body> </html> 

When I launch in the browser, it shows the facebook button and redirects clicks to new windows for FB logging, but then shows the above error!

+4
source share
3 answers

I know this is an old question, but here is a proven and working solution for everyone who ends up looking for an answer here:

At the beginning of App Domains field should be empty.

Click the "Add Platform" button below and select "Website."

In the new site form, you can add localhost in the Site URL field:

eg. http://localhost:3000/

For a visual guide with images, you can check this answer .

Alternatively, you can actually use answer123 answer and map localhost to a local domain (e.g. myproject.dev), and the local dev domain should be entered in the same Site URL field: for example. http://myproject.dev/

+15
source

You must use some kind of alias when you want to connect your Facebook application to your local environment.

Try the following:

  Go to your etc/hosts file and add the following line: 127.0.0.1 dev01.dev # you can change domain to whatever you want Go to Facebook App Dashboard and register your application using dev01.dev as domain! Add your Site URL (eg. http://dev01.dev/project/ ) It should works. 

Edit: you can also check this question: Facebook development in localhost

Source: facebook localhost developer

+2
source

On facebook, please refer to the following steps if the javascript SDK framework does not work in chrome.

  • Save application domain.
  • Site URL: localhost / App_Name

Disconnect all plugins from chrome. Especially an ad blocker that will give you:

307 Internal status code

It should work.

0
source

Source: https://habr.com/ru/post/1492024/


All Articles