让我首先说,我已经寻找这个问题的答案很长一段时间了……

我试图设置Facebook OAuth与我的应用程序,这是在我的机器上本地开发。Facebook授权的一切都很完美,直到我从使用localhost转移到另一个域名(仍然是我机器的本地域名)。现在我得到如下错误。

不能加载URL:这个URL的域不包括在应用程序的 域。要加载此URL,请添加所有域和子域 在你的应用程序设置的应用程序域字段。

我的hosts文件包含127.0.0.1 domain.dev(完美工作)

我的重定向在我的应用程序(使用Socialite)是http://domain.dev/auth/facebook/callback

在我的Facebook应用程序设置…

我的应用域名是Domain .dev 我的网站网址是http://domain.dev/ 我的有效OAuth重定向uri是 http://domain.dev/auth/facebook/callback

出现错误消息时的URL是..

https://www.facebook.com/v2.5/dialog/oauth?client_id=XXXXXXXXXXXXXXX&redirect_uri=http%3A%2F%2Fdomain.dev%2Fauth%2Ffacebook%2Fcallback&scope=email&response_type=code&state=0ztcKhmWwFLtj72TWE8uOKTcf65JmePtG95MZLDD

我不知道问题出在哪里。

屏幕截图1

屏幕截图2


当前回答

In the App domain section, you are writing your app domain but you also need to add your login domain i.e. the name of html page where you ask user to login. In my case, I was testing it on localhost and the login route was localhost/login, If I only put http://localhost.com in App domain section, I get this error. But after adding http://localhost/login.com, the error was fixed. and also the App settings has changed in newer version of SDK, in which there is no option for OAuth redirect route. You've to assign the redirect route directly from server side, after successfully getting OAuth token.

其他回答

这招对我很管用:

这里需要了解的主要事情是:Facebook总是会检查“WWW”域。因此,首先确保www.your_domain.dev在您的浏览器上运行。

如果您的本地服务器上有多个虚拟主机,那么其他一些虚拟主机可能会覆盖“www.your_domain.dev”。请检查一下。 Apache将选择域的FIRST定义(或者端口,或者其他类似的术语——我不是这方面的专家,但从错误中学会了)。 对于这个虚拟主机覆盖,一个简单的快速修复方法是将“www.your_domain.dev虚拟主机定义”放在“httpd-vhosts.conf”文件的最上面。

进入“/apache/conf/http -vhosts.conf”,把这个放在文件的最上面:

<VirtualHost *:80>
<Directory "C:/your_app_folder_path/">
    Options FollowSymLinks Indexes
    AllowOverride All
    Order deny,allow
    allow from All
</Directory>
ServerName your_domain.dev
ServerAlias your_domain.dev
DocumentRoot "C:/your_app_folder_path/"
</VirtualHost>

###### FOR SSL #####
<VirtualHost *:443>
    DocumentRoot "C:/your_app_folder_path/"
    ServerName your_domain.dev
    ServerAlias www.your_domain.dev
    SSLEngine on
    SSLCertificateFile "conf/ssl.crt/server.crt"
    SSLCertificateKeyFile "conf/ssl.key/server.key"
    <Directory "C:/your_app_folder_path/">
        Options All
        AllowOverride All
        Require all granted 
    </Directory>
</VirtualHost>

下一步:如果你使用的是Windows系统,在“C:\Windows\System32\drivers\etc”目录下编辑你的“hosts”文件,添加两行:

127.0.0.1 your_domain.dev
127.0.0.1 www.your_domain.dev

接下来:重新启动Apache服务器,现在一切都应该工作了。


我希望这将帮助你并节省你的时间。 我几乎浪费了一整天的时间在网上搜索,绞尽脑汁也找不到任何有用的东西,直到我发现了这个。

开发者的Meta界面目前提供了两个地方,你可以在这里输入应用程序的域:“应用程序域”下的基本设置,以及“域管理器”下的高级设置。如果您的域仅在域管理器中列出,则SDK可能无法识别。

如果你的游戏没有服务器/站点(例如,如果你像我一样为Gameroom开发)-添加“https://apps.facebook.com/xxxxxxxxxxxxxxxxx”(把你的应用ID改为“xxxxxxxxxxxx”)到“Valid OAuth Redirect uri”。

如果您正在使用AWS Cognito,则在Facebook Login ->设置中添加URL https://<your-user-pool-domain>/oauth2/idpresponse到有效OAuth重定向uri

我浏览了网上的所有答案,但没有一个对我有用。

我一直得到这个错误:

JSSDK Unknown主机域 你托管Facebook Javascript SDK的域不在你应用的Javascript SDK主机域列表中。请在应用程序仪表板登录设置中指定主机域。

但最后,我找到了解决办法。在写这篇文章的时候(2022年10月下旬),我的情况是这样的:

访问https://developers.facebook.com/apps/your-app-id-here/fb-login/settings -注意:这个url在未来可能会改变。只要去你的开发者的应用程序->产品-> Facebook登录->设置 搜索JavaScript SDK允许的域 我的url是这样写的:https://www.website.com/。在我添加了非www版本之后,一切都解决了!https://website.com/

希望这也能解决其他人的问题!