我正在尝试在Facebook上显示用户朋友的随机个人资料图片,我试图自己解决这个问题但是它崩溃了登录按钮并且它不能正常工作。我在Javascript文件中实现的代码有什么问题?
以下是我尝试过的代码:
/* make the API call */
function getInfo() {
FB.api('/friend-list-id/members', 'GET', {
fields: 'first_name,last_name,name,id,picture.width(100).height(100)'
}, function (response) {
console.log(response);//Check the response in console
document.getElementById('status').innerHTML = "<img src='" + response.picture.data.url + "'><br>" + response.name;
});
使用Javascript:
window.fbAsyncInit = function() {
FB.init({
appId: '',
xfbml: true,
version: 'v2.5'
});
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
document.getElementById('status').innerHTML = 'We are connected.';
document.getElementById('login').style.visibility = 'hidden';
} else if (response.status === 'not_authorized') {
document.getElementById('status').innerHTML = 'We are not logged in.'
} else {
document.getElementById('status').innerHTML = 'You are not logged into Facebook.';
}
});
};
(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'));
// login with facebook with extra permissions
function login() {
FB.login(function(response) {
if (response.status === 'connected') {
document.getElementById('status').innerHTML = "<img src='http://www.webdevelopmenthelp.net/wp-content/uploads/2015/04/loading.gif' />";
document.getElementById('login').style.visibility = 'hidden';
getInfo();// Invoke it here
name();
} else if (response.status === 'not_authorized') {
document.getElementById('status').innerHTML = 'We are not logged in.'
} else {
document.getElementById('status').innerHTML = 'You are not logged into Facebook.';
}
}, {
scope: 'email'
});
}
// getting basic user info
function getInfo() {
FB.api('/me', 'GET', {
fields: 'first_name,last_name,name,id,picture.width(100).height(100)'
}, function(response) {
console.log(response);//Check the response in console
document.getElementById('status').innerHTML = "<img src='" + response.picture.data.url + "'><br>" + response.name;
});
/* make the API call */
function getInfo() {
FB.api('/friend-list-id/members', 'GET', {
fields: 'first_name,last_name,name,id,picture.width(100).height(100)'
}, function (response) {
console.log(response);//Check the response in console
document.getElementById('status').innerHTML = "<img src='" + response.picture.data.url + "'><br>" + response.name;
});
}
提前完成
答案 0 :(得分:0)
在函数登录
中添加范围foreach my $table ($te->tables) {
foreach my $row ($table->rows) {
push @arr, @$row;
print @$row;
}
}
user_friends
功能好友
{scope: 'email,user_friends'}
只有安装此应用的朋友才会在API v2.0及更高版本中返回。 total_count in summary表示朋友的总数,包括尚未安装该应用的朋友。
阅读documentatiónhttps://developers.facebook.com/docs/graph-api/reference/v2.5/user/friends