如何记住邀请的朋友到Facebook应用程序?

时间:2014-02-09 22:49:41

标签: javascript facebook facebook-graph-api

我正在为Facebook创建游戏,这里是Invite friends功能。

现在如果用户邀请朋友,在关闭并打开邀请框朋友后再次出现在列表中。我需要该应用程序记住哪些朋友已经被邀请,他们不应该出现在列表中。

现在我的代码如下:

<div id="fb-root"></div>
<a href="#" onclick="FbRequest('This page is amazing, check it out!','4d5da07acbbb0');"><center>Invite Friends</center></a>
<script type="text/javascript">
window.onload = function () {


window.onload =FbRequest('This page is amazing, check it out!','4d5da07acbbb0');
}
function FbRequest(message, data){
        FB.ui({method:'apprequests',message:message,data:data,title:'Share this site with your friends'},
                function(response){
                        // response.request_ids holds an array of user ids that received the request
                }
        );
}

// typical application initialization code for your site
(function() {
    var e = document.createElement('script');
    e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
    e.async = true;
    document.getElementById('fb-root').appendChild(e);
}());
window.fbAsyncInit = function() {
    FB.init({
        appId   : '00000000',
        session : {},
        status   : true,
        cookie  : true,
        xfbml   : true
    });
};

</script>

我正在使用代码示例,这里是注释行:// response.request_ids holds an array of user ids that received the request也许这就是我需要的,我不知道如何正确使用它。

1 个答案:

答案 0 :(得分:0)

  1. 您需要一种方法来保留请求信息。如果您有后端服务提供程序(即运行php和mysql的Web服务器),您可以将请求的ID发送到您的服务器,以便通过ajax存储在数据库中。如果您没有后端服务提供商,那么您只有其他选择是客户端存储,例如“本地存储”,应视为易失性。

  2. 在调用app request对话框之前的某个时刻,您需要从上面步骤1中实现的存储设备获取您之前发送到的ID的列表。我想这取决于你的游戏加载方式,但有很多方法可以做到这一点。例如,如果您的页面是在php中动态生成的,则可以将所有id的javascript数组转储到HTML输出中。

    一个更好的方法可能是弹出一个微调器,“请等待......”,ajax获取已经发送的id,然后在你的ajax回调函数中,关闭微调器弹出窗口并调用facebook具有您的排除ID列表的特定功能。

  3. here in the documentation您可以看到需要填写的exclude_ids参数。

相关问题