开发者

How do I display the name of a user, in Facebook, using their uid?

开发者 https://www.devze.com 2023-03-06 03:53 出处:网络
I am loading the JavaScript SDK Asynchronously for my iframe canvas ap开发者_高级运维plication.

I am loading the JavaScript SDK Asynchronously for my iframe canvas ap开发者_高级运维plication.

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?


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!


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");).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号