how to detect fan of a facebook page
some days ago, i was facing a critical problem of facebook page. i was stuck for more than 2 days to get the solution. detecting facebook fan is very easy in application’s canvas page or application’s tab page in user’s profile. i’ve given a screenshot of tab profile in a facebook page.
user will add my app in facebook page’s tab. now i’ve to detect if viewer user is a fan of that page or not. if viewer user is a fan of that page then i’ll show some special info to him, but if he isn’t fan of that page then i’ll not show him the special info. this will inspire user to become a fan of a given page.
if you write
you’ll get info like this:
Array ( [fb_sig_in_canvas] => 1 [fb_sig_request_method] => GET [fb_sig_is_admin] => 0 [fb_sig_type] => LOCAL_BUSINESS [fb_sig_is_fan] => 0 [fb_sig_locale] => en_US [fb_sig_in_new_facebook] => 1 [fb_sig_time] => 1242633535.5921 [fb_sig_added] => 0 [fb_sig_page_id] => XXXXXXXXX [fb_sig_page_added] => 1 [fb_sig_profile_user] => XXXXXXXXX [fb_sig_profile_id] => XXXXXXXXX [fb_sig_in_profile_tab] => 1 [fb_sig_api_key] => XXXXXXXXX [fb_sig_app_id] => XXXXXXXXX [fb_sig] => XXXXXXXXX )
if you see the actual info you’ll find, though user logged in facebook, but you’ll not get his id anyhow in facebook page’s tab profile. or another thing you’ll notice fb_sig_is_fan is remain same ‘0’ all time whether user is a fan or not
Facebook fixed the problem and now if a user is a fan of your page you’ll see fb_sig_is_fan = 1, so now you can avoid the <fb:visible-to-connection> solution and only just check the fb_sig_is_fan parameter to detect whether user is a fan of your page or not.
[fb_sig_is_fan] => 1
at last i got the solution and it is very easy, just write below code and place fan info (special info for fan) within fb:visible-to-connection tag. so now special info will only shown to the fan user of a facebook page
<fb:fbml version="1.1"> <fb:visible-to-connection> Welcome, fans! blah blah blah... </fb:visible-to-connection> </fb:fbml>
Some of my friends ask me to show a perfect example. So please follow the below comment and code. You can copy this code in static fbml app and test.
Check the following link to see real example: http://www.facebook.com/pages/Thinkdiffnet/314110374728?v=app_4949752878
Developers please keep in your mind If you’re admin of facebook page, you all time see the fan restricted item and non fan restricted item. So use this code as example and must check a non admin facebook user’s account
<div> <div style="height: 800px;"> <!-- start non-fan part --> <div class="top"> Become fan and see deepika </div> <!-- end non-fan part --> <fb:fbml version="1.1"> <fb:visible-to-connection> <div style="position: absolute; top:2px;left:0px; width:100%; background-color:white"> <img src="http://s245.photobucket.com/albums/gg59/sathishcoumar/actress/deepika_sex_pictures_picture.jpg" alt='deepika' /> </div> </fb:visible-to-connection> </div> </div>
for more info visit: http://wiki.developers.facebook.com/index.php/Fb:visible-to-connection