简体   繁体   English

通过应用程序网站重定向到Facebook应用程序

[英]Redirect to facebook app through app-website

I have made an app as a Page Tab. 我已经做了一个应用程序作为页面选项卡。 I need to redirect to the facebook-app if someone opens the website url directly. 如果有人直接打开网站网址,我需要重定向到facebook-app。 For that, I need to check the content of the address bar and if it doesn't contain www.facebook.com inside it, I will redirect to the facebook-app url. 为此,我需要检查地址栏的内容,如果其中不包含www.facebook.com,我将重定向到facebook-app网址。 But, the problem is that inside the facebook iframe I am unable to get the content of the address bar. 但是,问题是在Facebook iframe中,我无法获取地址栏的内容。

Can you please tell me a good way to enable redirect to the fb-app in case someone accesses my website url directly? 如果有人直接访问我的网站网址,您能告诉我一种启用重定向到fb-app的好方法吗?

Probably the easiest way to achieve this, is to do next check in JavaScript : 可能最简单的方法是在JavaScript进行下一步检查:

if (window.top !== window){
  window.location = 'http://facebook.com/YOUR_PAGE?sk=v_YOUR_APP_ID'
}

If you are wanting to redirect to a tab, a more complete way of doing this is checking for the 'page' parameter that is only sent through in the signed request for a page tab. 如果要重定向到选项卡,一种更完整的方法是检查“ page”参数,该参数仅在已签名的页面选项卡请求中通过发送。

The reason being that only checking for the signed request will allow users to access your 520px tab app in a Facebook canvas (ie https://apps.facebook.com/yourapp which may not be what you want. 原因是仅检查已签名的请求才能使用户访问Facebook画布中的520px选项卡应用程序(即https://apps.facebook.com/yourapp可能不是您想要的)。

So for example 所以举个例子

    $fb = new Facebook( array(
                          'appId' => <your_app_id>, 
                          'secret' => <your_app_secret>); 
    $sr = $fb -> getSignedRequest();

And then redirect the user as they hit the page 然后在用户点击页面时将其重定向

    if (!($sr['page'])) {
        die('<script>window.top.location = "<your_tab_url>"</script>');
    };

Facebook posts a signed request parameter when you open an app in fanpage. 当您在粉丝专页中打开应用程序时,Facebook会发布签名的请求参数。

You can check if that parameter is null or not. 您可以检查该参数是否为null。

In php, 在php中

if(isset($_REQUEST["signed_request"]){
// Opened in facebook
}else{

//opened outside facebook.
}

In asp.net 在asp.net

    if(Request.Form["signed_request"] !=null)
    { 
      // Opened in facebook
}
else
{
// opened outside facebook.
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM