【问题标题】:How do I display the name of a user, in Facebook, using their uid?如何使用用户的 uid 在 Facebook 中显示用户的姓名?
【发布时间】:2011-05-14 22:30:06
【问题描述】:

我正在为我的 iframe 画布应用程序异步加载 JavaScript SDK。

我知道 fbml 已被弃用并被逐步淘汰,但 xfbml 还可以吗?

我还能使用 fb:name 吗? <fb:name uid="2901279">?

例如,有没有更好的方法为用户打印 100 个朋友的姓名?

【问题讨论】:

    标签: javascript facebook fbml xfbml uid


    【解决方案1】:

    您需要开始使用 Graph API,这里有一个快速工作示例来帮助您入门:

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

    只需替换为您的应用程序 ID 即可!

    【讨论】:

      【解决方案2】:

      您说得对,您可能不应该再使用fbml,但“社交插件”中的所有标记仍将受到鼓励(即like button)。

      无论它是否被弃用,我更喜欢完全控制我的应用程序的布局 - 而不是使用&lt;fb:name... 标签,您可以从“http://graph.facebook.com/UID/friends”获取所有朋友列表并解析结果JSON。 (在 PHP-SDK 中:$fb-&gt;api("/me/friends");)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-08-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-10-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多