Domanda

I am loading the JavaScript SDK Asynchronously for my iframe canvas application.

I am aware that fbml is deprecated and being phased out, but is xfbml still ok?

Can I still use fb:name eg. <fb:name uid="2901279">?

Is there a better way to print the names of 100 friends for a user, for example?

È stato utile?

Soluzione

You need to start using the Graph API, here's a quick working example to get you started:

<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>Facebook Javascript SDK</title>
</head>
<body>
    <div><fb:login-button perms=""></fb:login-button></div>

    <div id="friends"></div>


    <div id="fb-root"></div>
    <script>
      window.fbAsyncInit = function() {
        FB.init({
          appId   : 'APP_ID',
          cookie  : true,
          status  : true,
          xfbml   : true 
        });

        FB.Event.subscribe('auth.login', function(response) {
          window.location.reload();
        });

        FB.api('/me/friends',function(resp) {
            if(resp && resp.data.length) {
                var html = '<ul>';
                for(var i=0; i<resp.data.length; i++) {
                    html += '<li><img src="http://graph.facebook.com/' + resp.data[i].id + '/picture?type=small" />' + resp.data[i].name + '</li>';
                }
                html += '</ul>';
                document.getElementById('friends').innerHTML = html;
            }
        });
      };

      (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>
</body>
</html>

Just replace with your application id and you are good to go!

Altri suggerimenti

You have right, you probably shouldn't use fbml any longer, but all markup from "social plugin" will be still encourage (i. e. like button).

No matter is it deprecated or not, I prefer got full controll of layout my app - Instead use <fb:name... tag, you could get all friends list from "http://graph.facebook.com/UID/friends" and parse resulting JSON. (in PHP-SDK: $fb->api("/me/friends");).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top