首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Facebook Graphs API发布照片和标记朋友

使用Facebook Graphs API发布照片和标记朋友
EN

Stack Overflow用户
提问于 2012-06-01 10:42:00
回答 3查看 7.5K关注 0票数 2

我有这段代码,它会发布到用户的墙上:

代码语言:javascript
复制
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的文档真的很难理解,而且它并没有给出任何如何做到这一点的例子,所以请不要只给我一个他们的文档的链接,因为我已经阅读了他们的任何相关的东西,但我仍然无法做到这一点。

我也尝试过了,但没有成功:

代码语言:javascript
复制
FB.api('/me', function(response){
                var userId = response.id;
                FB.api('/'+response.id+'/tags/'+userId, {
                    to: $("#recipientID").val()
                }, function(response){
                    console.log(response)
                });
            }); 
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-06-01 12:51:40

我最终设法破解了它,这是一个与我使用的不同的调用:

代码语言:javascript
复制
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);
         }
      });
    }
}); 
票数 3
EN

Stack Overflow用户

发布于 2012-06-01 12:28:50

你不能同时上传和标记好友,你必须先上传,然后再标记好友。如果有更多的超过朋友,那么你必须使用循环逐个标记它们,否则将不起作用,

票数 1
EN

Stack Overflow用户

发布于 2013-03-20 10:28:31

我从这篇文章中的代码开始,在一张照片中标记多个人。它在我的代码库中工作,我已经尝试过提炼它,但它可能需要更多的工作,不确定。我想这可能会对想做同样事情的人有所帮助。

如果任何人有任何改进的想法,我洗耳恭听:

代码语言:javascript
复制
//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');
                }
            });
        }
    });
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10843749

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档