gpt4 book ai didi

javascript - 如何在 Facebook 中使用他们的 uid 显示用户的姓名?

转载 作者:行者123 更新时间:2023-11-30 13:33:01 25 4
gpt4 key购买 nike

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

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

我还能使用 fb:name 例如。 <fb:name uid="2901279">

例如,有没有更好的方法来为用户打印 100 个 friend 的名字?

最佳答案

您需要开始使用图谱 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,您就可以开始了!

关于javascript - 如何在 Facebook 中使用他们的 uid 显示用户的姓名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6005202/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com