相当于 FB.Facebook.get_isInCanvas 的新 SDK 是什么

发布于 2024-12-25 03:25:06 字数 212 浏览 1 评论 0原文

试图找到新的 Facebook javascript sdk 相当于:

FB.Facebook.get_isInCanvas

是否也有这种调用的 PHP SDK 方式?

我需要测试是否在画布内,标头检查和signed_request 检查无法确定用户是否在应用程序内的 Facebook 上...除非我没有正确的检查方法...

Trying to find the new Facebook javascript sdk equivalent to:

FB.Facebook.get_isInCanvas

Is there a PHP SDK way of this call as well?

I need to test if inside the canvas, and header checks and signed_request checks do not determine if user is on Facebook within the Application...unless I don't have the right way of checking...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

满意归宿 2025-01-01 03:25:06

FB._inCanvas 是您想要从 Facebook JS SDK 获得的内容,但我发现有时并不总是设置,所以让我们看看他们自己如何进行检查并复制:

var _inCanvas: (
  (window.location.search.indexOf('fb_sig_in_iframe=1') > -1) ||
  (window.location.search.indexOf('session=') > -1)
);

请参阅 https://github.com/facebook/facebook-js-sdk/blob/master/src/core/prelude.js#L71

更新
其新版本是:

((window.location.search.indexOf('fb_sig_in_iframe=1')>-1)||
(window.location.search.indexOf('session=')>-1) ||
(window.location.search.indexOf('signed_request=')>-1) ||
(window.name.indexOf('iframe_canvas')>-1) ||
(window.name.indexOf('app_runner')>-1))

FB._inCanvas is what you want from the Facebook JS SDK however that i found is sometimes not always set so lets see how they themselves do the check and copy that:

var _inCanvas: (
  (window.location.search.indexOf('fb_sig_in_iframe=1') > -1) ||
  (window.location.search.indexOf('session=') > -1)
);

See https://github.com/facebook/facebook-js-sdk/blob/master/src/core/prelude.js#L71

UPDATE
The newer version of this is:

((window.location.search.indexOf('fb_sig_in_iframe=1')>-1)||
(window.location.search.indexOf('session=')>-1) ||
(window.location.search.indexOf('signed_request=')>-1) ||
(window.name.indexOf('iframe_canvas')>-1) ||
(window.name.indexOf('app_runner')>-1))
笙痞 2025-01-01 03:25:06

使用 PHP-SDK,如果您的 $_REQUEST/$_POST 中有 signed_request,则可以假定应用程序在画布中运行。不完全安全,但在大多数情况下可以假设它......

JS-SDK 可以通过检查 window.top == window 来确定它没有在画布中运行,如果你需要知道你是在画布中,而不仅仅是某人的框架中。

更新:
刚刚检查过,JS-SDK 中有一个更好的选项来检查您是否在画布中运行,但我不确定这种行为将来不会改变。你可以使用这样的东西:

var pageInfo = FB.Canvas.getPageInfo();
var isInCanvas = (pageInfo && pageInfo.clientWidth == 0);

Using PHP-SDK you can assume application running in canvas if you have signed_request in your $_REQUEST/$_POST. Not fully safe but may be ok to assume it in most cases...

JS-SDK can say that it's not running in canvas for sure only by checking window.top == window not very useful if you need to know you're in canvas and not just someone's frame.

Update:
Just checked and there is a better option in JS-SDK to check if you running in canvas but I'm not sure this behavior wouldn't change in future. You can use something like this:

var pageInfo = FB.Canvas.getPageInfo();
var isInCanvas = (pageInfo && pageInfo.clientWidth == 0);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文