jquery - How to check if fan likes my facebook page without triggering "likes" permission -


in facebook application built using vs2012 template not want have facebook permissions request.

the app meant act fan gate facebook page. adapted code below app specific settings. code how check if user likes facebook page or url using facebook's api. app pops facebook permissions check allow access likes.

is there technique check likes work in environment using?

<html>   <head>     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>     <style type="text/css">       div#container_notlike, div#container_like {         display: none;       }     </style>   </head>   <body>     <div id="fb-root"></div>     <script>         window.fbasyncinit = function () {             fb.init({                 appid: 'your_app_id', // app id                 channelurl: 'http(s)://your_app_domain/channel.html', // channel file                 status: true, // check login status                 cookie: true, // enable cookies allow server access session                 xfbml: true  // parse xfbml             });              fb.getloginstatus(function (response) {                 var page_id = "your_page_id";                 if (response && response.authresponse) {                     var user_id = response.authresponse.userid;                     var fql_query = "select uid page_fan page_id = " + page_id + "and uid=" + user_id;                     fb.data.query(fql_query).wait(function (rows) {                         if (rows.length == 1 && rows[0].uid == user_id) {                             console.log("like");                             $('#container_like').show();                         } else {                             console.log("no likey");                             $('#container_notlike').show();                         }                     });                 } else {                     fb.login(function (response) {                         if (response && response.authresponse) {                             var user_id = response.authresponse.userid;                             var fql_query = "select uid page_fan page_id = " + page_id + "and uid=" + user_id;                             fb.data.query(fql_query).wait(function (rows) {                                 if (rows.length == 1 && rows[0].uid == user_id) {                                     console.log("like");                                     $('#container_like').show();                                 } else {                                     console.log("no likey");                                     $('#container_notlike').show();                                 }                             });                         } else {                             console.log("no likey");                             $('#container_notlike').show();                         }                     }, { scope: 'user_likes' });                 }             });         };          // load sdk asynchronously         (function (d) {             var js, id = 'facebook-jssdk'; if (d.getelementbyid(id)) { return; }             js = d.createelement('script'); js.id = id; js.async = true;             js.src = "//connect.facebook.net/en_us/all.js";             d.getelementsbytagname('head')[0].appendchild(js);         }(document));     </script>      <div id="container_notlike">       don't me :(     </div>      <div id="container_like">       me :)     </div>    </body> </html> 

as cbroe said, way know if user likes page, without asking likes permission, it's using signed request on page tabs.

if app page tab, on index file signed request posted.

the signed_request posted json object usual signed request:

{    "oauth_token": "...big long string...",    "algorithm": "hmac-sha256",    "expires": 1291840400,    "issued_at": 1291836800,    "registration": {       "name": "paul tarjan",       "email": "fb@paulisageek.com",       "location": {          "name": "san francisco, california",          "id": 114952118516947       },       "gender": "male",       "birthday": "12/16/1985",       "like": true,       "phone": "555-123-4567",       "anniversary": "2/14/1998",       "captain": "k",       "force": "jedi",       "live": {          "name": "denver, colorado",          "id": 115590505119035       }    },    "registration_metadata": {       "fields": "[\n {'name':'name'},\n {'name':'email'},\n {'name':'location'},\n {'name':'gender'},\n {'name':'birthday'},\n {'name':'password'},\n {'name':'like',       'description':'do plugin?', 'type':'checkbox',  'default':'checked'},\n {'name':'phone',      'description':'phone number',             'type':'text'},\n {'name':'anniversary','description':'anniversary',              'type':'date'},\n {'name':'captain',    'description':'best captain',             'type':'select',    'options':{'p':'jean-luc picard','k':'james t. kirk'}},\n {'name':'force',      'description':'which side?',              'type':'select',    'options':{'jedi':'jedi','sith':'sith'}, 'default':'sith'},\n {'name':'live',       'description':'best place live',       'type':'typeahead', 'categories':['city','country','state_province']},\n {'name':'captcha'}\n]"    },    "user_id": "218471" } 

if parse json object array , if app page tab doing this, signed_request['page']['liked'] you'll true if user likes page or false if doesn't.

you can read more parsing sign requeste here: https://developers.facebook.com/docs/howtos/login/signed-request/

and more specific fields each app type, here: https://developers.facebook.com/docs/reference/login/signed-request/


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -