Facebook Application Tab -> External Linking with PHP

后端 未结 4 778
失恋的感觉
失恋的感觉 2021-02-01 07:58

I currently have an Application on the Facebook Tab, and am wondering if there is a way for me to deep link into an item on that app tab. Example:

User is in the applic

相关标签:
4条回答
  • 2021-02-01 08:11

    Perhaps.

    For Application Canvas Pages, Facebook forwards any addition URI information to your canvas callback.

    For example, if your app page is http://apps.facebook.com/testapp

    and your canvas callback is http://facebook.example.com/testapp/canvas

    Then going to http://apps.facebook.com/testapp/foo?bar=baz would result in facebook's servers hitting yours like so http://facebook.example.com/testapp/canvas/foo?bar=baz.

    I've never tested it to see if application tabs share this behavior, but it's worth a shot. If so, you could just use URI information to drive your deeplinking.

    Also, you should be aware of the impending changes to application tabs.

    0 讨论(0)
  • 2021-02-01 08:18

    For those that need a full (yet minimal working) example (like myself) here is the index.php which does the deep-linking when needed. Make sure you've downloaded the Facebook PHP SDK and that your require path points to it. (Obviously, you also need to replace the $app_id and $app_secret with your own app info.)

    <?php
    require 'facebook-php-sdk/src/facebook.php';
    
    $app_id     = "YOUR_APP_ID_HERE";
    $app_secret = "YOUR_APP_SECRET_ID_HERE";
    
    $facebook = new Facebook(array(
        'appId'  => $app_id,
        'secret' => $app_secret
    ));
    
    $signed_request = $facebook->getSignedRequest();
    
    // Get app_data from signed request POST
    $app_data = $signed_request["app_data"];
    
    // Parse app_data & Re-direct
    if ($app_data) {
        header("HTTP/1.1 302 Found");
        header("Location: {$app_data}");
    exit;
    }
    
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns:fb="http://www.facebook.com/2008/fbml" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Title Here</title>
    </head>
    <body>
        <h1>Landing Page</h1>
    </body>
    </html>
    

    Also, make sure that within your FB App Settings, all your URL paths (i.e. Canvas URL, Page Tab URL, etc) end with a backslash, or else you'll get some 301 redirect errors.

    Once your app is setup and you've added it your fan page, you can deep link with something like:

    http://www.facebook.com/pages/MYFANPAGE/XXXXX?sk=app_XXXXX&app_data=sub/another.php
    

    You may have to parse the actual app_data value before using it, but for me it worked just as above.

    Hope that helps others out there. Of course, Facebook may change all this at any time.

    0 讨论(0)
  • 2021-02-01 08:19

    So far, we have not been able to deep link to an application Tab using URL parameters.

    We are able to retrieve window.location information from an application page (e.g. http://apps.facebook.com/testapp/foo?bar=bar)

    This does not work on an app Tab (e.g. http://www.facebook.com/testpage?v=app_1234&bar=bar)

    Similarly, we cannot use $_GET['foo'] to try to grab it server-side if we are in a Facebook tab.

    If anyone has managed to get around this, I'd love to know the solution.

    0 讨论(0)
  • 2021-02-01 08:21

    Here's how we deep link to subpages within our app's Page Tab.

    When your application lives inside a Page Tab, Facebook will strip out all GET params except for app_data. It passes app_data inside the signed_request parameter of the POST data.

    More info in the docs: https://developers.facebook.com/docs/authentication/signed_request/

    So when we build links to subpages, it will look something like

    http://www.facebook.com/myfanpage?sk=app_XXXXXX&app_data=%2Fmainpage%2Fsubpage
    

    Then, in our index page code, we check for the app_data param. If it exists, then a simple 302 redirect does the trick.

    $request = parse_signed_request($_POST['signed_request']);
    if ($request['app_data'])
    {
        header('HTTP/1.1 302 Found');
        header('Location: {$request['app_data']}');
        exit;
    }
    

    Note: you can pass more than 1 param inside of app_data using a URL-encoded, JSON-array or something like that.

    0 讨论(0)
提交回复
热议问题