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

时间:2013-08-01 05:42:46

标签: php javascript facebook facebook-javascript-sdk

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

以下代码有效,但无论用户发送了多少邀请,它都只会有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>

2 个答案:

答案 0 :(得分:1)

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

根据第V.1节。

  

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

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

  

“应用程序集成点”是指应用程序信息部分,   应用程序选项卡,订阅源,请求(包括邀请),发布者,收件箱   附件,聊天,书签或用户个人资料的任何其他功能   或Facebook的沟通渠道   应用程序可以提供,显示或传送指向,打开的内容   代表或经用户许可。

答案 1 :(得分:0)

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

当我运行与此类似的邀请码时:

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"
  ]
}

因此,共振对象中总有两个条目,其中一个是'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');
});

但我不知道有任何政策允许这样做,所以这是你应该阅读的主题。

相关问题