Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
722 views
in Technique[技术] by (71.8m points)

oauth 2.0 - What am I doing wrong in localhost Facebook app development?

App Domains: localhost
Website with Facebook login: http://localhost/auth

I go to http://localhost/auth/ and in my Chrome developer console I see the error: Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains.

I do a view-source to see the following:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<div id="fb-root"></div>
<script>
  // Additional JS functions here
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'myappidremovedfromstackoverflowquestion', // App ID
      channelUrl : '//localhost/auth/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });

    // Additional init code here

  };

  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));
</script>
<p>hello</p>
</body>
</html>

I go to http://localhost/auth/channel.html and view source to see the single line:

<script src="//connect.facebook.net/en_US/all.js"></script>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should use some alias domain when you want to connect your Facebook application with your local environment.

Try the following:

  1. Go to your etc/hosts (or %systemroot%/system32/drivers/etc/hosts) file and add the following line:

    127.0.0.1 foo.local # alias domain

  2. Go to App > Settings and register your application by simply using foo.local as app domain.

  3. Add your Site URL (e.g. http://foo.local/project/ )

  4. Done.

Edited on 16.01.2016:

Facebook has changed their UI, follow these steps to make it works.

  1. Go to App > Settings > Basic (tab)
  2. Click on Add Platform, select "Website" and enter your alias domain.
  3. Add your domain in App Domain section.
  4. Done.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...