我为我的iframe canvas应用程序异步加载JavaScript SDK。如何使用他们的uid在Facebook中显示用户的名称?
我知道fbml已被弃用并逐步淘汰,但是xfbml仍然可以吗?
我还可以使用fb:name eg。 <fb:name uid="2901279">
?
有没有更好的方式来为用户打印100个朋友的名字,例如?
我为我的iframe canvas应用程序异步加载JavaScript SDK。如何使用他们的uid在Facebook中显示用户的名称?
我知道fbml已被弃用并逐步淘汰,但是xfbml仍然可以吗?
我还可以使用fb:name eg。 <fb:name uid="2901279">
?
有没有更好的方式来为用户打印100个朋友的名字,例如?
你需要开始使用图形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只需更换,你是好去!
你有权利,你可能不应该再使用fbml
,但所有来自“社交插件”的标记仍然会被鼓励(即like button
)。
无论是过时与否,我更喜欢有布局的全面控制研究我的应用程序 - 而是使用<fb:name...
标签,你可以得到所有的朋友列表,从“http://graph.facebook.com/UID/friends”和解析结果JSON
。 (在PHP-SDK中:$fb->api("/me/friends");
)。