This is a continuation of my previous article, 5 Facebook Application Gotchas.

  1. User invites

    Everyone loves user invites. Well, every application developer, at least. Requests are achieved by calling $facebook->api_client->notifications_sendRequest(…). Facebook only allows you to send notifications to ten users at a time, however.

    To implement an invite page create a URL called, say, http://apps.facebook.com/myapp/process. You have a form which lets users select their friends who haven't installed the app, as follows

    global $facebook;
    $fql = "SELECT uid, strlen(books)
                FROM user
                WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = {$facebook->user})
                AND has_added_app = 0"
    ;
    $uids = $facebook->api_client->fql_query($fql);
    // Render the form using the above UIDS
     

    Have the form you render submit to /process, which should behave roughly as follows

    global $facebook;
    if (isset($request['uids'])) {
        if (empty($request['uids']))
            $facebook->redirect('APP URL');

        $array = explode(',', $request['uids']);
    } elseif (isset($request['users'])) {
        $array = array_keys($request['users']);
    } else {
        $facebook->redirect('APP URL');
    }

    $uids = array();
    while (count($array) > 0 and count($uids) < 10) {
        $uids[] = array_shift($array);
    }

    $url = $facebook->api_client->sendRequest($uids, 'MyApp', $msg, $img_url, true);

    if ($url) {
        $facebook->redirect($url . "&canvas=1&next=" . urlencode("process?uids=" . implode(',', $array)));
    } else {
        $facebook->redirect('APP URL');
    }

    Note, the next parameter tells the request URL where to redirect after a batch has been processed. If it is a canvas page you should include canvas=1.

  2. CSS ids

    Facebook only allows inline styles and styles within style tags. To prevent you from affecting the layout of the rest of Facebook it inserts a wrapper div around your content and assigns it an id of the form app_XXXX, where XXXX is your application ID number. It then affixes #app_XXXX to all your CSS rules.

    This means that, for example, CSS hacks which involve things like html > * won't work since they will come out as #app_XXXX html > * on the other side. For ID rules, however, it does something much more annoying: it rewrites the ID itself. So, e.g., a rule like #MyDiv h1 becomes #app_XXXX_MyDiv h1 rather than #app_XXXX #MyDiv h1. There's no good reason for this, AFAIK, but it means using IDs on a page inside Facebook becomes tedious — you need to know your application ID number.

    To work around this I just uses classes when writing Facebook pages.

  3. Facebook is Strict

    In order to strip out bad elements and alter the CSS Facebook actually lexes and parses your code. And it is strict. Like, really strict — much more strict than any browser.

    If you're the developer you can see the error messages and I advise you to clean them up. With CSS at least bad elements just get dropped. I'd also bet money than acceptance into the application directory is contingent on you outputting well-formed FBML.

  4. Use an Icon

    The process for what applications get accepted and what applications get rejected from the application directory is totally opaque. The best we have is that an application must "work," have at least five users, have an icon, and follow the TOS.

    Looking over the application directory you see plenty of apps with terrible icons, so the quality doesn't so much matter as presence does. Just create one and upload it before you submit your application to the directory. You can change it later if you want, but you won't get accepted without one.

  5. No conditional comments

    The Facebook JavaScript doesn't always play nice with IE. That is, you can find permutations which work in Safari and Firefox but fail in IE. Shucks. Unfortunately Facebook doesn't allow conditional comments which would give you the ability to let your application degrade nicely in IE.

    What's more, because of the way Facebook rewrites CSS, most of the CSS hacks don't work. Facebook does, however, pass along the user agent when it requests data from your server, so if you must absolutely have browser-specific code you'll have to push the logic back into the PHP (or Java, if you swing that way).

I had a sixth gotcha but I forgot what it was. Oops!

4 Comments

  1. Shannon -jj Behrens June 26th, 2007 / 12:22 am

    Helpful. Thanks!

  2. Pedram July 10th, 2007 / 7:33 pm

    I didn’t want to set the wrong tone on my last response. I really enjoy reading your blog posts and think you have some interesting views. You have my email so please shoot me a line and we can chat.

  3. Jesse July 11th, 2007 / 11:40 pm

    Pedram,

    Oh, no, no hard feelings at all. The messup was 100% mine. Even after the retraction I felt like your critique just made the whole article basically worthless. It was a good lesson in the important of research.

    I wasn’t trying to cover up my idiocy or anything (as you can see it’s not really hard to get me to admit it), but I just thought the article no longer served any purpose.

  4. jon August 29th, 2007 / 2:38 pm

    Could you give me a hand with two problems I have with my app?

    1) The images on my app don´t look good. This is ture of both the images taken from my site as well as those taken from facebook (e.g., profile picture of users). Has any of you stumble upon that issue? if so, any ideas on how to solve it? I am sure this is the kind of things that are dead simple to solve but I just can´t find the solution..
    here is the link to see how they look:

    http://www.flickr.com/photos/12356701@N02/1266654735/

    2) i need use js in my app, i need the onclick event. for example.

    function accept()
    {
    location.href=”index.php”;
    }

    how i can do this with fbjs?

    Thanks in advance!!!

Leave a Reply