我有这段代码,它会发布到用户的墙上:
FB.api('/me/photos', 'post', {
message:'photo description',
url:imgURL
}, function(response){
console.log(response);
if (!response || response.error) {
console.log(response);
}else{
FB.api(response.id+'/tags/me', {
to: $("#recipientID").val()
}, function(response){
console.log(response)
});
}
}); 第一部分运行得很好,我只是想不出如何在其中标记一个朋友,我的标记调用返回了一个空数组。Facebook的文档真的很难理解,而且它并没有给出任何如何做到这一点的例子,所以请不要只给我一个他们的文档的链接,因为我已经阅读了他们的任何相关的东西,但我仍然无法做到这一点。
我也尝试过了,但没有成功:
FB.api('/me', function(response){
var userId = response.id;
FB.api('/'+response.id+'/tags/'+userId, {
to: $("#recipientID").val()
}, function(response){
console.log(response)
});
}); 发布于 2012-06-01 12:51:40
我最终设法破解了它,这是一个与我使用的不同的调用:
FB.api('/me/photos', 'post', {
message:'Checking tags',
url:imgURL
}, function(response){
if (!response || response.error) {
console.log(response);
}else{
//tags friend
var postId = response.id;
FB.api(postId+'/tags?to='+friendID, 'post', function(response){
if (!response || response.error) {
console.log(response);
}
});
}
}); 发布于 2012-06-01 12:28:50
你不能同时上传和标记好友,你必须先上传,然后再标记好友。如果有更多的超过朋友,那么你必须使用循环逐个标记它们,否则将不起作用,
发布于 2013-03-20 10:28:31
我从这篇文章中的代码开始,在一张照片中标记多个人。它在我的代码库中工作,我已经尝试过提炼它,但它可能需要更多的工作,不确定。我想这可能会对想做同样事情的人有所帮助。
如果任何人有任何改进的想法,我洗耳恭听:
//Set empty array of Friend ID's
var friendIds = []
//Get friend ID's
getFriendById = function(id) {
var i, len;
id = id.toString();
for (i = 0, len = friends.length; i < len; i += 1) {
if (friends[i].id === id) {
return friends[i];
}
}
friendIds.push(friends);
};
var postToWall = function(){
//Assign Friends to variables
var name1 = getFriendById(friendIds[0]);
var name2 = getFriendById(friendIds[1]);
var name3 = getFriendById(friendIds[2]);
//Set empty array for tags
var tags = [];
//Loop through friends and make an array ready for posting
$.each(selectfriends, function(i,friend){
var new_tag = {tag_uid: friend};
tags.push(new_tag);
})
//Post photo to wall
FB.api('/me/photos', 'post', {
message:'Enter custom message',
url: 'link/to/photo.jpg'
}, function(response){
console.log(response)
if (!response || response.error) {
console.log('error');
} else {
//Tag Friends
var postId = response.id;
//Use stringify to send the array in string to facebook
FB.api(postId+'/tags?tags='+JSON.stringify(tags), 'post', function(response){
if (!response || response.error) {
console.log('error');
}
});
}
});
}https://stackoverflow.com/questions/10843749
复制相似问题