0

I want to display the facebook recommendations plugin when user is login into facebook. I don't want to show the plugin when user is not logged into facebook because the result looks unpleasing. Is this even possible? How would I implement this to my site?

Thank you in adavance! Maca

facebook social plugin (Recommendations) https://developers.facebook.com/docs/reference/plugins/recommendations/

I already have the Javascript SDK like below implemented in the page. I also have jQuery1.5.2 loaded in the page.

    <div id="fb-root"></div> <script>  
     window.fbAsyncInit = function() {
         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
          channelUrl  : 'http://urltomysite.com/channel.html' // custom channel
         });   }; 

       (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>

Here is the tag for recomendations plugin

<fb:recommendations site="urltomysite.com" width="300" height="300" header="true" font="" border_color=""></fb:recommendations>
Maca
  • 1,659
  • 3
  • 18
  • 42

1 Answers1

1

You can use FB.getLoginSTatus to check if a user is logged into FB. With the response from this function, you can decide whether to show your recommendation or not.

   FB.getLoginStatus(function(response) {
   if (response.session) {
         // logged in and connected user, someone you know
        } else {
        // no user session available, someone you dont know
        }
  });

Also Check : Check if user is logged in New Facebook API

Community
  • 1
  • 1
Balanivash
  • 6,709
  • 9
  • 32
  • 48
  • I know Im asking too much but I just started to learn Javascript. I wrote this code but it doesn't seem to work. `function fbLoginStatus(response) { if(response.session) { document.getElementById('fb-root').innerHTML = ""; } else { document.getElementById('fb-root').innerHTML = "

    YOU ARE NOT LOGGED IN

    "; } }`
    – Maca Jul 11 '11 at 06:18
  • Check the console if you are getting any error, if yes what is the error, and I'm not sure I can tell anything without knowing what error you are getting as the js seems to be fine. – Balanivash Jul 11 '11 at 06:26