2
votes

I am able to send app request using request dialog to 50 of a user's friends with to= field modification but I want to send requests to all of a user's friends like this example app does: Invite your friend button for pages

This app invites users first 50 friends than again invites users next 50 friends and so on

In my code I forward the users to this URL using PHP

https://www.facebook.com/dialog/apprequests?app_id=443468799026324
&to=" . $friend_ids .  "
&max_recipients=50&filters=app_non_users
&redirect_uri=" . urlencode($canvas_page2)  . "
&message=" . $message;

Facebook offical guide for request dialogue

How do I proceed from here?

1
Sounds like you are requiring your users to invite all their friends to your application... that is against FB policy... Allow your users to select certain friends to invite otherwise you stand the risk of hitting the request limit for your application...Lix
@Lix this is not necessary if user wants he can first he click invite button and return to index page but if he click again invite button than he will found new 50 usersDanish Iqbal
@Lix can you please more explain this "Allow your users to select certain friends to invite otherwise you stand the risk of hitting the request limit for your application." is this limit for single user or for all users ?Danish Iqbal
If each user sends each of their friends an invite - unless a large number of them accept the invite, limitations will be enforced on your application. Right now you have a certain limit of requests that your application can send per user per day. The more invites you send blindly the more risk you are at for getting negative feedback from users (that means declining requests or blocking your application)Lix
ok @Lix Thank you so much :) so nice of you :)Danish Iqbal

1 Answers

4
votes

You can do this as follow: First you set 50 friends id in to parameter and store remaining friends id in cookie now when you send request then it redirects to your site url where you can repeat above step.i.e. send 50 friends request and store remaining in cookie.

var to="";
    for(var j=0 ; j< 50 && j<friends.length ; j++){
        if(friends[j].checked == true){
            to += friends[j].value;
            if(j != friends.length-1 && j != 49){
                to += ',';
            }
        }
    }
    var redirect_uri=your_site_url+"?button=inviteresponse";
    var callbackto="";
    for(var i=j;i<friends.length;i++){
        callbackto += friends[i].value;
        if(i != friends.length-1){
            callbackto += ',';
        }
    }
    document.cookie = "param="+callbackto+";path=/";
    var url="https://www.facebook.com/dialog/apprequests?app_id="+app_id+"&to="+to+"&message=Checkout apps&redirect_uri="+redirect_uri;
    window.open(url,'', 'width=900,height=500,resizable=yes,scrollbars=yes');  

case "inviteresponse":
        if (empty($_COOKIE['param'])) {
            unset($_COOKIE['param']);
            echo "<script type='text/javascript'>window.close();</script>";
            die();
        } else {
            $friends = explode(",", $_COOKIE["param"]);
            $to = "";
            for ($j = 0; $j < 50 && $j < count($friends); $j++) {
                $to .= $friends[$j];
                if ($j != count($friends) - 1 && $j != 49) {
                    $to .= ",";
                }
            }
            $redirect_uri = your_site_url+"?button=inviteresponse";
            $callbackto = "";
            for ($i = $j; $i < count($friends); $i++) {
                $callbackto .= $friends[$i];
                if ($i != count($friends) - 1) {
                    $callbackto .= ",";
                }
            }
            unset($_COOKIE['param']);
            setcookie("param", $callbackto);
            $url = "https://www.facebook.com/dialog/apprequests?app_id=" . APP_ID . "&to=" . $to . "&message=Checkout apps&redirect_uri=" . $redirect_uri;
            header("Location: " . $url);
        }