我如何使用jsp文件中的Javascript从Facebook API获取Getfriends列表
How can I get Get friends list from Facebook API using Javascript in a jsp file
当他登录我的网站时,我正试图获得一个用户基本配置文件和朋友列表,如(friendId、freindName等)。但目前我正在获取基本配置文件,我现在的问题是获取朋友列表并显示它。
这是我的代码
<body>
<script>
// This is called with the results from from FB.getLoginStatus().
function statusChangeCallback(response) {
console.log(response);
if (response.status === 'connected') {
// Logged into your app and Facebook.
testAPI();
} else if (response.status === 'not_authorized') {
// The person is logged into Facebook, but not your app.
document.getElementById('status').innerHTML = 'Please log ' + 'into this app.';
} else {
document.getElementById('status').innerHTML = 'Please log ' + 'into Facebook.';
}
}
// This function is called when someone finishes with the Login
// Button. See the onlogin handler attached to it in the sample
// code below.
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
}
//this is to initialize the
window.fbAsyncInit = function() {
FB.init({
appId : 'my_app_id',
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse social plugins on this page
version : 'v2.1' // use version 2.1
});
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
};
// Load the SDK asynchronously
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
// Here we run a very simple test of the Graph API after login is
// successful. See statusChangeCallback() for when this call is made.
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Successful login for: ' + response.name);
document.getElementById('status').innerHTML = 'User id, ' + response.id + '!';
document.getElementById('status1').innerHTML = 'User name, ' + response.name +'!';
});
//the sort function to sort the list of friends
function sortMethod(a, b) {
var x = a.name.toLowerCase();
var y = b.name.toLowerCase();
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}
// now to get friends where my problem is found
//var limit = 10;
FB.api('/me/friends', function(response) {
var result_holder = document.getElementById('result_friends');
var friend_data = response.data.sort(sortMethod);
var results = '';
for (var i = 0; i < friend_data.length; i++) {
results += '<div><img src="https://graph.facebook.com/' + friend_data[i].id + '/picture">' + friend_data[i].name + '</div>';
}
// and display them at our holder element
result_holder.innerHTML = '<h2>Result list of your friends:</h2>' + results;
});
}
</script>
<div class="fb-login-button"
scope="public_profile, email, user_friends"
onlogin="checkLoginState();"
data-auto-logout-link="true">
</div>
// here it's working
<div id="status"></div> //so i get the user id
<div id="status1"></div> //and here the user name as espected
<div id="fb-root"></div>
//this is to display the like button and share no problem and it also working
<div
class="fb-like"
data-share="true"
data-width="450"
data-show-faces="true"
data-size="large">
</div>
// But here nothing is displaying and nothing like error in the console
<div id="result_friends"></div>
求你了,我真的很感激任何能帮助我的人thks提前
我正在处理同样的问题。这是Facebook改变其API的结果。现在,只有使用同一应用程序的朋友才会出现在结果中。只有对于游戏开发商,才有一个额外的选项来邀请尚未成为同一应用程序已知用户的朋友。
如果你的应用程序不是一款游戏,那么从一开始就很难扩大你的客户群。
相关文章:
- Backbone/Facebook API未按预期工作
- 骨干Facebook API函数
- Facebook API过滤用户活动,只显示指定的好友
- Facebook API:确定FB.ui发送方法的收件人数量
- 使用Facebook api获取专辑封面
- 正在运行时检测Facebook API版本
- 将HTML文本输入传递给Facebook API javascript调用
- 正在获取用户'通过Facebook API庆祝生日
- 什么是我过时的Facebook API调用
- Facebook API-发布到用户墙
- PHP使用Facebook API随机结束或中断
- 如何从服务器进行Facebook API调用?要使用的令牌
- Count Taggable Friends Facebook API
- Facebook API - 检测会话是否处于活动状态
- 在小部件中使用Facebook API
- 使用Facebook API将图像和评论发布到用户墙的简单方法
- Facebook Api获取好友总数,但不是好友数据
- Facebook API:访问页面对话
- Facebook Api V2.2 Fql query
- Javascript Facebook API - 无法提取朋友的生日或其他信息