【问题标题】:What am I doing wrong in localhost Facebook app development?我在 localhost Facebook 应用程序开发中做错了什么?
【发布时间】:2013-04-24 01:30:21
【问题描述】:
App Domains: localhost
Website with Facebook login: http://localhost/auth

我转到 http://localhost/auth/ 并在我的 Chrome 开发者控制台中看到错误: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.

我做了一个视图源来查看以下内容:

<!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>

我去http://localhost/auth/channel.html查看源码看单行:

<script src="//connect.facebook.net/en_US/all.js"></script>

【问题讨论】:

    标签: facebook oauth-2.0 facebook-javascript-sdk facebook-oauth


    【解决方案1】:

    当您想将 Facebook 应用程序与本地环境连接时,您应该使用一些别名域。

    尝试以下方法:

    1. 转到您的etc/hosts(或%systemroot%/system32/drivers/etc/hosts)文件并添加以下行:

      127.0.0.1 foo.local # alias domain

    2. 转到App &gt; Settings,只需使用foo.local 作为应用程序域即可注册您的应用程序。

    3. 添加您的网站 URL(例如 http://foo.local/project/

    4. 完成。

    于 2016 年 1 月 16 日编辑:

    Facebook 已更改其 UI,请按照以下步骤使其正常工作。

    1. 转到App &gt; Settings &gt; Basic (tab)
    2. 点击Add Platform,选择“网站”并输入您的别名域。
    3. App Domain 部分添加您的域。
    4. 完成。

    【讨论】:

    • 由于 SO watchdongs 不允许我编辑答案,我将发布正确的部分作为评论:问题是在某个时间点我在高级下设置了有效 OAuth 重定向 URI设置为不同的东西,这会覆盖所有其他设置。清空该字段可以解决问题,但当然正确的解决方法是将该字段设置为我想要接收访问令牌的特定 URL。
    • 除此之外,如果您使用的是自定义端口,例如127:0.0.1:8080,对我来说,它只有在我在 Facebook 的应用程序破折号中添加端口时才有效。所以在/etc/hosts 127.0.0.1,但是在FB:127.0.0.1:8080
    猜你喜欢
    • 2016-06-10
    • 1970-01-01
    • 1970-01-01
    • 2013-08-06
    • 2010-10-12
    • 2021-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多