简体   繁体   中英

How to remember invited friends to Facebook app?

I'm creating game for Facebook, here is Invite friends function.

For now If user invite friend, after It close and open invite box friend appears on the list again. I need that app remembered which friends are already invited and they should not appear on list.

For now my code looks like:

<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>

I'm useing code example and here is commented line: // response.request_ids holds an array of user ids that received the request maybe this is what I need just I don't know how to use It correctly.

  1. You need a way to persist the request information. If you have a backend service provider (ie a web server running php and mysql), you could send the requested id's to your server for storing in the database via ajax. If you don't have a backend service provider, you're only other option is client side storage such as "local storage" which should be regarded as volatile.

  2. At some point before the app request dialog is called, you need to get a list of the id's you have previously sent to, from the storage device implemented in step 1 above. I guess it depends on how your game is loaded, but there are a lot of ways of doing this. If your page is generated dynamically in php for example, you could dump a javascript array of all the id's into the HTML output.

    A nicer way might be to pop-up a spinner with "please wait...", ajax to get the id's already sent to, and then in your ajax callback function, close the spinner pop-up and call the facebook specific function with your list of exclusion id's.

  3. And here in the documentation you can see the exclude_ids parameter you need to fill.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM