0
<div class="like-button">

            <div class="fb-like-box" data-href="https://www.facebook.com/pages/Annupurnas-Cooking/526672940684211?ref=hl" data-width="292" data-show-faces="true" data-stream="true" data-header="true"></div>

            <div id="fb-root"></div>
            <script type="text/javascript">
                <!--
                var fbAsyncInit = function() {

                    var APP_ID   = '324859924285629';
                    var PAGE_ID  = '526672940684211';

                    FB.init({
                        appId  : APP_ID,
                        status : true, // check login status
                        cookie : true, // enable cookies to allow the server to access the session
                        xfbml  : true  // parse XFBML
                    });

                    FB.Event.subscribe('auth.sessionChange', function(response) {
                        if(response.session){
                            //check to see if user is a fan of the page
                            var query = FB.Data.query( 'select page_id from page_fan where uid='+response.session.uid+' and page_id ='+PAGE_ID);
                            query.wait( function(rows) {
                                if(rows.length){
                                    //user already likes your page
                                }else{
                                    //user has not yet liked your page
                                }
                            });
                        }else{
                            //user has not yet logged in
                        }
                    });

                    FB.Event.subscribe('edge.create', function(response) {
                        //user just clicked "like" on your page
                    });

                    FB.Event.subscribe('edge.remove', function(response) {
                        //user just clicked "unlike" on your page
                    });
                };

                (function() {
                    var e = document.createElement('script');
                    e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
                    e.async = true;
                    document.getElementById('fb-root').appendChild(e);
                }());
                //-->
            </script>


        </div>

I want to implement the like button of my facebook page. I want to check that current user have liked us or not. can someone tell me how we can do this.

in the code I put my appId and facebook page ID. I tried to use it but it's told me in error that "An active access token must be used to query information about the current user.".

do someone know how I can put access-token to this. Do I need to put accesstoken for like kind of functionality.

user1814971
  • 167
  • 1
  • 2
  • 14

1 Answers1

1

Check here: API -> User

You can check if a User likes a specific page by issuing an HTTP GET to /PROFILE_ID/likes/PAGE_ID. This requires the user_likes (current user) or friends_likes (current user's friend) permission.

When you have user_likes permission you can easily check against graph api: https://graph.facebook.com/me/likes/PAGE_ID&access_token=xxxxxxxxx

Alexander Nenkov
  • 2,910
  • 20
  • 28
  • Can you check this http://stackoverflow.com/questions/13399352/how-to-check-if-facebook-fanpage-is-liked/13404944#13404944 – user1814971 Jan 09 '13 at 14:15
  • WOW I have seen your comment their 2 min ago. IS their noway to simply check it without permission. – user1814971 Jan 09 '13 at 14:16
  • the above quote is from the official documentation. You can check users likes and get results for people whose likes are public. But a lot of users hide that info. And then comes the permission. – Alexander Nenkov Jan 09 '13 at 14:18
  • you can make JS fql calls with SDK. Check this out: http://stackoverflow.com/questions/7599865/facebook-javascript-sdk-for-fql-with-additional-parameter – Alexander Nenkov Jan 09 '13 at 17:52
  • I tried to use page and app both and it's work without permission. – user1814971 Jan 11 '13 at 08:08