3

I'm wondering about this: I have a simple facebook-connect app that will only show certain content after you login and liked a certain page. It works (huzzah!) but I want to make it more user friendly by making it refresh automatically after you pressed the like button.

Here's some code:

<?php
if ($me) {

    $pageid = -----------;
    $uid = $me['id'];

    $likeID = $facebook->api(
        array( 'method' => 'fql.query', 'query' =>
        'SELECT target_id FROM connection WHERE source_id = ' . $uid . ' AND target_id = ' . $pageid )
        );

    if ( empty($likeID) ) 
    {
        // Person is LOGGED IN, but has NOT LIKED
        echo '<script src="MY WEBPAGE"></script><fb:like href="MY WEBPAGE" layout="box_count" show_faces="false" width="450"></fb:like>';
    } 
    else
    {
        // Person is LOGGED IN, and has LIKED, score!
        echo 'Download link';
    }
}
else
{
    // Person is NOT LOGGED IN, so we know NOTHING
    echo '<script src="MY WEBPAGE"></script><fb:like href="MY WEBPAGE" layout="box_count" show_faces="false" width="450"></fb:like>';
} ?>

Is there anything I can do to this code (maybe in the fb:like tag?) that makes it reload the page after a like?

Thanks.

joon
  • 832
  • 13
  • 31

1 Answers1

6

As you are using the XFBML implementation, I assume the JS library (http://connect.facebook.net/en_US/all.js#xfbml=1) is already loaded, so what you need is just this snippet:

<script>
FB.Event.subscribe('edge.create', function(response) {
    window.location.reload();
});
</script>
ifaour
  • 38,035
  • 12
  • 72
  • 79
  • Yes! It didn't work at first, but after some digging it turned out Wordpress adds random

    tags all over making my javascript break right after the facebook connection (that's why I didn't realize it sooner). (There's a nice WP plugin to disable this: "wpautop control")

    – joon Feb 12 '11 at 18:45