Forums

Simple Facebook Connect
[resolved] detect if user already pressed "like" (19 posts)

  1. MegaToon TV
    Member
    Posted 1 year ago #

    Hi,

    Is there a way that you can detect if the user already "liked" or "shared" your page?

    I know in facebook fbml there's a simple code to do that:
    <fb:visible-to-connection>

    But the code above is not applicable to wordpress.

    Any idea? thanks

  2. MegaToon TV
    Member
    Posted 1 year ago #

    or how to know if user already "liked" your page?

  3. Otto
    Tech Ninja
    Posted 1 year ago #

    You can use the sfc_is_fan() function to determine if a viewer is a fan of your FB Application or Fan Page.

    But that won't return true if they "liked" one of the posts on your site, or if they shared it. It only returns true if they're a fan of your FB App/Page as a whole. This is what the "Like" button in the Fan Box/Like Box does, makes them like your area on Facebook.

  4. MegaToon TV
    Member
    Posted 1 year ago #

    I really did not know where to start at first but thanks so much for the idea Otto! it worked! :)

  5. Brayne
    Member
    Posted 8 months ago #

    sfc_is_fan() doesn't seem to work with the latest version. Can you point me in the right direction to detect if a WP user is a Fan of a Page, not an App?

    Thanks in advance!

  6. Otto
    Tech Ninja
    Posted 8 months ago #

    Never got around to fixing up that function before releasing 1.0. Just now fixed it up, you can find the updated function in the trunk's sfc-base.php:

    http://plugins.svn.wordpress.org/simple-facebook-connect/trunk/sfc-base.php

    Just use this new file and sfc_is_fan() should work again.

  7. Otto
    Tech Ninja
    Posted 8 months ago #

    Also note that like its predecessor, the sfc_is_fan() function has to make a call to Facebook's servers to determine if the user is a fan. So it may be slow, since it's making an external request. Therefore it wouldn't be a good idea to use it on every page load, but perhaps only for specific use-cases.

  8. Brayne
    Member
    Posted 8 months ago #

    Awesome, Thank you for you quick response! Perhaps checking for a fan, then storing the info for the session? Still testing so I don't use it for every page load.

    I found this on a blog that I thought I'd share as well. Thoughts?

    $request = $_REQUEST["signed_request"];
    list($encoded_sig, $load) = explode('.', $request, 2);
    $fbData = json_decode(base64_decode(strtr($load, '-_', '+/')), true);
    if (!empty($fbData["page"]["liked"]))
    { ?>
    You are a fan - insert html here
    <?php } else { ?>
    You are not a fan - insert html here
    <?php }
  9. Otto
    Tech Ninja
    Posted 8 months ago #

    No, that's a special case code. He's using that for a page that's running inside the Facebook canvas. Different situation.

  10. Brayne
    Member
    Posted 8 months ago #

    Cheers!

  11. ellebillias
    Member
    Posted 7 months ago #

    Hi how would you call this function?

    I want to show a fan-only offer on my WordPress site. Do the users have to actually connect with my site first for this to work or will it work if they are just logged in to Facebook.

    IE. if someone has liked my page before but hasn't visited my site then they should be shown the fan content because they are a Facebook fan.

    Thanks

  12. Otto
    Tech Ninja
    Posted 7 months ago #

    If they have never connected with your site, then your site has no way to know who they are and whether they are a fan or not.

    They have to connect at least once for the site to know their Facebook ID and thus be able to tell if they're a fan.

  13. ellebillias
    Member
    Posted 7 months ago #

    i thought so! would there be any way around this? i am building a mini-site using wordpress which is connected to an app on Facebook, so most users will viewing the site through the Facebook Page and be clicking the Like button on Facebook.

    Would there be anyway to connect them? There are plugins out there that integrate "reveal tabs" but only on a tab by tab basis, not site wide.

    Would you quote on creating something like that?

  14. Otto
    Tech Ninja
    Posted 7 months ago #

    I assume you mean that you're making a Canvas application of some sort? So that the website is visible to the user on a Facebook Page itself, in an iframe?

    In such a case, you still have to get the user to authorize the application in order to know who they are. This is talked about in the Authorization bit of https://developers.facebook.com/docs/appsonfacebook/tutorial/

    Now, SFC doesn't have any code specifically to handle Canvas applications. It's more geared towards building FB connectivity into your own site. If you're making a Canvas app, you'll probably want to use some custom code instead. However, some of the bits of SFC would be suitable for lifting out and using in your custom code. The registration (and base) plugin has some code to handle the signed_request, for example. You'd likely have to rework it to your specific needs though.

  15. ellebillias
    Member
    Posted 7 months ago #

    I am making a custom Facebook welcome page for a Facebook business page. Outside of WordPress it's easy, just create an index.php file and call the facebook.php file from the PHP SDK then you can use the $like_status variable to show fan and non-fan content.

    AKA reveal tab - this might help explain what I mean: http://www.hyperarts.com/blog/customizing-facebook-iframe-application-signed_request_reveal_tab/

  16. Otto
    Tech Ninja
    Posted 7 months ago #

    ellebillias: It's just as easy inside WordPress too, my point however was that SFC isn't made to do that sort of thing. It doesn't have any code to help create Canvas pages.

    On a Canvas page, you get different inputs than you do on non-Canvas pages. When your page is running inside Facebook, you get inputs from Facebook. Outside Facebook, you don't get those inputs. You don't have access to Facebook's cookies. That sort of thing.

    A canvas page runs in the Facebook domain. SFC is designed to run on WordPress sites not in the Facebook domain.

  17. ellebillias
    Member
    Posted 7 months ago #

    Ok, thanks so SFC doesn't work like that. Do you know anyone who could write something that would accomplish what I want?

  18. Otto
    Tech Ninja
    Posted 7 months ago #

    Why not just do it the same way as you discussed earlier? You can include the facebook.php code from inside your theme file easily enough. It'll work just the same.

  19. ellebillias
    Member
    Posted 7 months ago #

    It's not working though! Hence my frustration!

    I called the facebook.php file and added to the init via the theme functions file

    but calling the session variable it returns blank

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic