Java Facebook 登录:无法加载 URL 此 URL 的域未包含在应用程序域中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37652221/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Facebook Login :Can't Load URL The domain of this URL isn't included in the app's domains
提问by Vartika
I know many such questions have already been asked tried a lot then after posting the question. My Problem is still unresolved.
我知道很多这样的问题在发布问题后已经被问过很多次了。我的问题仍然没有解决。
I have a web application where I embedded the Facebook login using Oauth Authentication. I used the following code for help Facebook login with Java
我有一个 Web 应用程序,我在其中使用 Oauth 身份验证嵌入了 Facebook 登录信息。我使用以下代码帮助Facebook 使用 Java 登录
Till last month it was working fine but from few days we are coninuously getting the Error : -
直到上个月它工作正常,但从几天开始,我们不断收到错误:-
Can't Load URL The domain of this URL isn't included in the app's domains. To be able to load this URL, add all domains and subdomains of your app to the App Domains field in your app settings.
无法加载 URL 此 URL 的域未包含在应用程序的域中。为了能够加载此 URL,请将您应用的所有域和子域添加到应用设置中的“应用域”字段。
**Setting used are following:-
Website url : **https://www.enggheads.com/**
App Domain : **enggheads.com**
Redirect uri :
1. https://www.enggheads.com/#!login
2. https://www.enggheads.com/#!signup**
SCREENSHOTS:
截图:
So, I just want to know whats the issue why I am facing this problem. Is there something which I am missing in the settings section?
所以,我只想知道我面临这个问题的原因是什么。我在设置部分缺少什么吗?
UPDATE
更新
Code flows :
代码流:
Step1. On button click url called--->
第1步。在按钮上单击 url 调用 --->
"http://www.facebook.com/dialog/oauth?" + "client_id="
+ FB_APP_ID + "&redirect_uri="
+ URLEncoder.encode(REDIRECT_URI, "UTF-8")
+ "&scope=public_profile ";
I am receiving error on this very part where it gives error Can't Load URL The domain of this URL isn't included in the app's domains. To be able to load this URL, add all domains and subdomains of your app to the App Domains field in your app settings.
我在这部分收到错误,它给出错误 无法加载 URL 此 URL 的域未包含在应用程序的域中。为了能够加载此 URL,请将您应用的所有域和子域添加到应用设置中的“应用域”字段。
采纳答案by SkyWalker
I want to share 2 ways for making solution. Hope it will solve your issue.
我想分享两种制作解决方案的方法。希望它能解决你的问题。
Solution 1:
解决方案1:
Facebook now roles some features as plugins. In the left hand side select Products and add product. Then select Facbook Login. Pretty straight forward from there, you'll see all the Oauth options show up.
Facebook 现在将某些功能用作插件。在左侧选择产品并添加产品。然后选择 Facebook 登录。从那里直接开始,您会看到所有 Oauth 选项都显示出来。
OR,
或者,
Select Products and add product. Then select Facbook Login.
选择产品并添加产品。然后选择 Facebook 登录。
Then added http://localhost:3000/to the field 'Valid OAuth redirect URIs'
, and then everything worked.
然后将http://localhost:3000/ 添加到字段中'Valid OAuth redirect URIs'
,然后一切正常。
Solution-2:
解决方案 2:
It usually happens if you have entered the wrong details when you created the App in Facebook. Or have you changed a URL's of an existing App?
如果您在 Facebook 中创建应用程序时输入了错误的详细信息,通常会发生这种情况。或者您是否更改了现有应用程序的 URL?
Can you please recheck the settings of your APP in this page?
能否请您在此页面重新检查您的 APP 设置?
https://developers.facebook.com/apps
https://developers.facebook.com/apps
- Select the correct App and click in the edit button;
- Check the URLs & paths are correctly entered and are pointing to the site where you have installed Ultimate Facebook plugin.
- 选择正确的App,点击编辑按钮;
- 检查 URL 和路径是否正确输入并指向您安装 Ultimate Facebook 插件的站点。
Credit goes to Lei lionel
幸得雷莱昂内尔
UPDATE1:
更新1:
I think your access token already expires. So you need to extend access token. For this, please go through this link:
我认为您的访问令牌已经过期。所以你需要扩展访问令牌。为此,请访问此链接:
Resource Link:
资源链接:
UPDATE2:
更新2:
I just want to ask 1 thing more is it possible the app domain error has smthng to do with access token expiration time?
我只想再问一件事,应用域错误是否可能与访问令牌过期时间有关?
Ans:
答:
Generating Long-Lived User Tokens from Server-Side Long-Lived Tokens
从服务器端长寿命令牌生成长寿命用户令牌
Facebook has an advanced option for obtaining long-lived access tokens for apps that:
Facebook 有一个高级选项可以为以下应用获取长期访问令牌:
- Have their own authentication system (using a username/password for example)
- Store, on their servers, a Facebook access token for people using it that they send to different clients (browser or native mobile apps)
- Make API calls from all of those clients
- 拥有自己的身份验证系统(例如使用用户名/密码)
- 在他们的服务器上存储一个 Facebook 访问令牌,供使用它的人发送给不同的客户端(浏览器或本地移动应用程序)
- 从所有这些客户端进行 API 调用
If your app is set up like this it should use the process described here to obtain an access token from each client to avoid triggering Facebook's automated spam systems. The end result will be that each client will have its own long-lived access token.
如果您的应用是这样设置的,它应该使用此处描述的过程从每个客户端获取访问令牌,以避免触发 Facebook 的自动垃圾邮件系统。最终结果将是每个客户端都将拥有自己的长期访问令牌。
At a high level, this is how you can obtain a long-lived token from the client:
概括地说,这是从客户端获取长期令牌的方法:
- Make a call to Facebook's server from your server using a valid and current long-lived token to generate a code. (This assumes you've already obtained a long-lived token via Facebook Login. If the token you're using is invalid or expired, you'll have to obtain a new one by making the person using your app log in again.)
- Securely send that code to the client.
- The client then exchanges the code for a long-lived token.
- The client can use the long-lived token to post stories or query data.
- 使用有效且当前有效的长期令牌从您的服务器调用 Facebook 的服务器以生成代码。(这假设您已经通过 Facebook 登录获得了一个长期存在的令牌。如果您使用的令牌无效或已过期,您必须通过让使用您的应用程序的人再次登录来获得一个新令牌。)
- 将该代码安全地发送给客户端。
- 然后客户端将代码交换为长期存在的令牌。
- 客户端可以使用长寿命令牌发布故事或查询数据。
Getting the code
获取代码
Using a long-lived user access token, make a call to the following endpoint:
使用长期存在的用户访问令牌,调用以下端点:
https://graph.facebook.com/oauth/client_code?access_token=...&client_secret=...&redirect_uri=...&client_id=...
You need to give input: access_token, client_secret, redirect_uri and client_id.
您需要提供输入: access_token, client_secret, redirect_uri and client_id.
Response will be:
响应将是:
The response will look something like:
响应将类似于:
{"code": "...."}
Redeeming the code for an access token
兑换访问令牌的代码
Once you've retrieved the code from Facebook's server you then need to ship it to the client via a secure channel. Once that's done, you need to make a request from the client to this endpoint:
从 Facebook 的服务器检索代码后,您需要通过安全通道将其发送到客户端。完成后,您需要从客户端向此端点发出请求:
https://graph.facebook.com/oauth/access_token?code=...&client_id=...&redirect_uri=...&machine_id= ...
The call requires the following arguments:
该调用需要以下参数:
client_id - Yes
code - Yes
redirect_uri - Yes
machine_id - No
client_id - 是
代码 - 是的
redirect_uri - 是
machine_id - 否
The response will look like:
响应将如下所示:
{"access_token":"...", "expires_in":..., "machine_id":"..."}
回答by Rolintocour
I had such trouble because in the oauth redirection URL I only put : - http://example.com/#/redirect-urlwhereas I also had to put : - http://example.com
我遇到了这样的麻烦,因为在 oauth 重定向 URL 中我只放了: - http://example.com/#/redirect-url而我也不得不放: - http://example.com
Even if I only want to redirect to /#/redirect-url. Maybe the ajax sites cause troubles.
即使我只想重定向到 /#/redirect-url。也许 ajax 站点会引起麻烦。
回答by Vladimir Tolstikov
My issue was in that I not specified redirect_uri
which is required if user not logged-in with Facebook.
我的问题是我没有指定redirect_uri
如果用户没有使用 Facebook 登录是必需的。