Creating my first Facebook PHP Application #7

Creating the Launcher Tab

In this section we will do the following: create a static HTML tab in our Fan Page, which will provide a link to the Blogulike application IF the user has liked the Face Answers Fan Page. We will then amend the Blogulike application so that if the user hasn’t liked Face Answers, they will get redirected to the Static Tab we just created.

Creating the Static HTML tab

We covered this in detail in a previous article. So if you can’t follow this, view that one first.

1. Create a new Static FBML page as shown.

Creating a Facebook Application - Part 7.1

2. Test that your new tab works.

Creating a Facebook Application - Part 7.2

3. Amend the html of the tab to read as follows:

<h1>The New Home For Router Info</h1>

<fb:visible-to-connection>
<fb:else>
<p>That's right, Router Info is evolving. It will now be running as its own Facebook Application. To use it, simply like our Fan Page and you will gain access.</p>
</fb:else>
</fb:visible-to-connection>

<h1>The following content is visible to fans only</h1>
<fb:visible-to-connection>
<p>Click the link below to experience Boofulike</p>
<a href="http://apps.facebook.com/boofulike">Boofulike</a>
</fb:visible-to-connection>

I was worried when I added the above link, that Facebook would open up a new window to display it in. If you recall we had demonstrated previously that that is what Facebook does with links in Fan Page tabs. However, I need not have worried, as when you click the link Facebook detects you are staying within Facebook and the application replaces your fan page, rather than opening a new window. This is exactly what I wanted!

4. Test that it works again. Remember though, that if you are testing it with the Fan Page Admin Account, then you will see all HTML. IE the conditions tags will be ignored.

Creating a Facebook Application - Part 7.3

5. While you are viewing the fan page tab, copy the url. In our case it was:


http://www.facebook.com/pages/Face-Answers/142393235804950?v=app_7146470109

6. Click the boofulike link to make sure it is working.

Creating a Facebook Application - Part 7.4

7. Amend the boofulike php application to read as follows:

<?php

include_once "../src/facebook.php";
$cfa = "142393235804950";
$cboofid = "141486015903901";
$cboofsecret = "40566518e6c252d5accf406bd216b9eb";

$facebook = new Facebook(array('appId' => '141486015903901', 'secret' =>
    '40566518e6c252d5accf406bd216b9eb', 'cookie' => true, 'domain' =>
    'facebookanswers.co.uk'));

$session = $facebook->getSession();

if (!$session) {
    $url = $facebook->getLoginUrl(array('canvas' => 1, 'fbconnect' => 0));

    echo "<p>Redirecting to permission request...</p>";
    echo "<script type=\"text/javascript\">top.location.href = '$url';</script>";
} else {

    try {
        $friends = $facebook->api('me/friends');
        $likes = $facebook->api('me/likes');

        $cmsg = "You no like us...";
        $lliked = false;
        foreach ($likes['data'] as $ilike) {

            if ($ilike['id'] == $cfa) {
                $cmsg = "You like " . $ilike['name'] . "!";
                $lliked = true;
                ;
            }
        }


        if ($lliked) {
            echo "Welcome, friend!";
            // Do the real application now!

            // End of real application.
        } else {
            // This is the URL of the fan page tab we created for the application.
            $url = 'http://www.facebook.com/pages/Face-Answers/142393235804950?v=app_7146470109';
            echo "<script type=\"text/javascript\">top.location.href = '$url';</script>";

        }


    }
    catch (FacebookApiException $e) {
        $url = $facebook->getLoginUrl(array('canvas' => 1, 'fbconnect' => 0));
        echo "Please wait for authorization…";
        echo "<script type=\"text/javascript\">top.location.href = '$url';</script>";
    }


}

I’ve removed most of the junk. However, if you are still lost, this is the key bit:

        if ($lliked) {
            echo "Welcome, friend!";
            // Do the real application now!

            // End of real application.
        } else {
            // This is the URL of the fan page tab we created for the application.
            $url = 'http://www.facebook.com/pages/Face-Answers/142393235804950?v=app_7146470109';
            echo "<script type=\"text/javascript\">top.location.href = '$url';</script>";

        }

Replace the URL above with whatever URL you noted in step 5 above.
8. Log on as a non-liking user and try running boofulike. You should be diverted to the boofulike loader tab. If this doesn’t work you have screwed up somewhere.

Creating a Facebook Application - Part 7.5

9. Like the application.

Creating a Facebook Application - Part 7.6

10. Run the application!

That all went rather smoothly. I’m possibly doing this all in a very silly fashion, however, I have at last found a method that works, so I am happy with that.

Next, we will be making the approved application do something.

You can skip to the end and leave a response. Pinging is currently not allowed.

Leave a Reply

Opposite of up:

Powered by WordPress | Cheap at&t cell phones for sale | Thanks to Sprint online specials, Video Game Music and Car Insurance