javascript 为什么我们需要在我们的服务器上创建一个 channel.html 来使用 Facebook JS SDK?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7052734/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 22:48:40  来源:igfitidea点击:

Why do we need to create a channel.html on our server to use Facebook JS SDK?

javascriptfacebookfacebook-javascript-sdk

提问by AppleGrew

I really don't understand why do we need to create channel.html file, as mentioned by FB docs. I also want to understand how it is used. In my logs I don't see this file being ever requested.

我真的不明白为什么我们需要创建 channel.html 文件,正如FB docs所提到的。我也想了解它是如何使用的。在我的日志中,我没有看到有人请求过这个文件。

采纳答案by Drew

The channel file is to provide a way to do cross domain communication between FB's servers and your own. The reason for this is their tight control over access tokens. You must authenticate a redirect url and app id to retrieve this access token. In order for them to pass you the token, they hit your URL with the access token in the hash. With the Channel URL, they get to pass this token to themselves (their JavaScript running on your domain).

频道文件是提供一种方式,在FB的服务器和你自己的服务器之间进行跨域通信。这样做的原因是他们对访问令牌的严格控制。您必须验证重定向 url 和应用程序 ID 才能检索此访问令牌。为了让他们将令牌传递给您,他们使用哈希中的访问令牌访问您的 URL。使用频道 URL,他们可以将此令牌传递给自己(他们在您的域上运行的 JavaScript)。

This channel file can then communicate the access token to your active page.

然后,此频道文件可以将访问令牌传送到您的活动页面。

For them to keep all of these things available to only their domain, they need something that works in every browser. Currently, that is a hack of creating popups that are not accessible by javascript running on your server.

为了让所有这些东西只对他们的域可用,他们需要在每个浏览器中都可以使用的东西。目前,这是一种创建无法通过在您的服务器上运行的 javascript 访问的弹出窗口的技巧。

回答by Dustin Nielson

Hope this helps.

希望这可以帮助。

https://developers.facebook.com/docs/reference/javascript/FB.init/

https://developers.facebook.com/docs/reference/javascript/FB.init/

From the doc:

从文档:

This is an option that can help address three specific known issues. First, when auto playing audio/video is involved, the user may hear two streams of audio because the page has been loaded a second time in the background for cross domain communication. Second, if you have frame busting code, then you would see a blank page. Third, this will prevent inclusion of extra hits in your server-side logs. In these scenarios, you may provide the optional channelUrl parameter:

这是一个可以帮助解决三个特定已知问题的选项。首先,当涉及自动播放音频/视频时,用户可能会听到两个音频流,因为页面已经在后台进行了第二次加载以进行跨域通信。其次,如果您有框架破坏代码,那么您将看到一个空白页面。第三,这将防止在您的服务器端日志中包含额外的点击。在这些场景中,您可以提供可选的 channelUrl 参数: