2

ユーザーのウォールに投稿する次のコードがあります。

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)
                });
            }); 
4

3 に答える 3

3

私はついにそれをクラックすることができました。それは私が使用していたものとは異なる呼び出しです:

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-01T04:51:40.047 に答える
1

この投稿のコードから始めて、写真に複数の人にタグを付けました。それは私のコードベースで動作します。私はそれを抽出しようとしましたが、さらに作業が必要になる可能性があります。同じことをしようとしている人に役立つかもしれないと考えました。

誰かが改善のためのアイデアを持っているなら、私はすべて耳にしています:

//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');
                }
            });
        }
    });
}
于 2013-03-20T02:28:30.920 に答える
1

同じ通話で友達をアップロードしてタグ付けすることはできません。最初にアップロードしてから友達にタグ付けする必要があります。友達よりも多い場合は、 loop を使用して 1 つずつタグを付ける必要があります。他は機能しません。

于 2012-06-01T04:28:49.777 に答える