简体   繁体   中英

Display facebook recommendations plugin when user is logged in

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>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM