Facebook应用程序-我如何计算发件人邀请的朋友数量


Facebook Application - How do i count the number of friends a sender invites?

我正在做这个facebook邀请(appequest),但我需要计算用户发出的邀请数量,有人能帮我吗?

下面的代码有效,但无论用户发送多少邀请,它都只计算1个邀请

<script>
    FB.init({
        appId:'<?=$myappid?>',
        cookie:true,
        status:true,
        xfbml:true
    });
    function FacebookInviteFriends()
    {//start of FacebookInviteFriends
        var inviteCounter = FB.ui({
            method: 'apprequests',
            message: '<?=$me['name']?> has invited you to play this game!',
            title: 'Select your friends to play this game!',
            exclude_ids: <?=$allFBStr?>,
            max_recipients: 5
        },
            function (inviteCounter) {
                var userID = '<?=$me['id']?>';
                //alert(userID);
                $.ajax({//ajax
                    type: 'POST',
                    url: 'addInvitationCounter.php',
                    data: {
                        userID: userID
                    },
                    success: function(result){
                        //alert("SUCCESS: " + result);
                        location.href = "myprofile.php";
                    },
                    error: function(result){
                        alert("ERROR: " + result);
                    }
                });
            }
        );
    }

</script>

我不知道我是否答对了你的问题,但这实际上违反了Facebook的政策。

根据第V.1节。

您不得激励用户授予额外权限或使用应用程序集成点。

根据有关应用程序集成点的文档

"应用程序集成点"是指应用程序信息部分,"应用程序"选项卡、"订阅源"、请求(包括邀请)、发布服务器、收件箱附件、聊天、书签或用户配置文件的任何其他功能或Facebook通信渠道应用程序可以在代表用户或通过用户的许可。

我曾经写过一个应用程序,你可以根据邀请的人数获得奖金,所以这是可能的。我认为您错过了响应对象的结构。

当我运行类似于以下的邀请代码时:

FB.ui({
    method: 'apprequests',
    message: 'XYZ has invited you to play this game!',
    title: 'Select your friends to play this game!'
}, function (response) {
    console.log(response);
});

这就是response的样子(ID已更改,请参阅XYZ)

{
  request: "634814526537XYZ",
  to: [
    0: "100000526972XYZ"
    1: "100000756092XYZ"
  ]
}

所以resonse对象中总是有两个条目,其中一个是"to",这是一个包含邀请id的数组。受邀人数的访问方式如下:

FB.ui({
    method: 'apprequests',
    message: 'XYZ has invited you to play this game!',
    title: 'Select your friends to play this game!'
}, function (response) {
    var numberOfInvites = response.to.length;
    alert('You have invited '+ numberOfInvites +'People');
});

但我不知道有什么政策允许这样做,所以这是一个你应该阅读的话题。