Javascript-获取一张用户的随机个人资料图片'的朋友在脸书上
Javascript - get one random profile picture of user's friends on 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;
});
}
提前Thanx
在函数登录中添加作用域user_friends
{scope: 'email,user_friends'}
功能好友
function getFriendRandom(cb) {
FB.api('/me/friends',{
fields: 'name,id,picture.width(100).height(100)'
}, function (response) {
if (response && !response.error) {
var random = Math.floor(Math.random()*response.data.length);
cb(response.data[random].picture.data.url);
}
});
}
//usage
getFriendRandom(function(image){
console.log(image);
});
API v2.0及更高版本仅返回安装此应用程序的好友。summary中的total_count表示好友总数,包括尚未安装该应用程序的好友。
阅读文档https://developers.facebook.com/docs/graph-api/reference/v2.5/user/friends
相关文章:
- AngularJS+Firebase上传个人资料图片
- 显示脸书好友个人资料图片时出现问题
- 如何在ionic中弹出个人资料图片
- Javascript-使用Facebook登录,显示用户's成功登录后的个人资料图片
- Javascript-获取一张用户的随机个人资料图片'的朋友在脸书上
- 推特小部件_bigger个人资料图片
- 如何使用JavaScript SDK更改Facebook个人资料图片并按时更改其背面
- 钛加载Facebook个人资料图片集成不起作用
- 在 Twitter API 版本 1.1 中拉取 Twitter 个人资料图片
- 如何获取电子邮件地址的Google+个人资料图片
- 如何在Meteor应用程序中显示facebook好友数量+个人资料图片
- 链接到网站上的当前Twitter个人资料图片和用户名
- Facebook Graph API-在进行身份验证之前获取个人资料图片
- 无法让用户在注册过程中上传个人资料图片(Parse.com/JS SDK)
- 使用Javascript上传个人资料图片
- 使用Web Camera拍摄个人资料图片并在画布中显示图片
- 使用谷歌登录,获取大型个人资料图片
- 在我的网站上显示推特个人资料图片和推特总数(我/任何用户的推特数)
- 使用facebook用户名获取facebook个人资料图片
- 检索Facebook个人资料图片的URL