开发者

why is exclude_ids parameter is not working in facebook application invitation?

this is my invitation code:

<?php 
$app_id = "12345678910112";
$canvas_page = "http://apps.facebook.com/apppage/";       

$con = new mysqli("localhost","username","password","dbname") or die(mysqli_connect_error()); 
$SQL=mysqli_query($con,"select the already invited friends");

$exclude_ids="";

while($row = mysqli_fetch_assoc($SQL))
{
$exclude_ids=$exclude_ids . "," . $row['inviteduserid']  ; 
}

mysqli_free_result($SQL);
mysqli_close($con);
// now the $exclude_ids will look like t开发者_StackOverflowhis 12321324,54621321,465498631,23184641  

$message = "join this cool app";
$filters = array('app_non_users');
$requests_url = "https://www.facebook.com/dialog/apprequests?app_id=" . $app_id 
. "&redirect_uri=" . urlencode($canvas_page) 
. "&message=" . $message 
. "&filters=" . json_encode($filters) 
. "&max_recipients=25" 
. "&exclude_ids=" . $exclude_ids;

?>

every thing is working very well except it is not excluding the invited friends. what is wrong with this?


A note on building comma separated strings : Its made much easier if you put them into an array first.

$excludeIdArr=[];
$excludeIdStr="";

while($row = mysqli_fetch_assoc($SQL))
{
    $excludeIdArr[]=$row['inviteduserid']; 
}

$excludeIdStr = implode(",",$excludeIdsArr);

You had an extra comma at the beginning of your list of ids...

In addition...The documentation of the requests dialog says the exclude_ids parameter takes an array.

exclude_ids
A array of user IDs that will be excluded from the dialog...


thanks Lix,but i don't know why is it still not working for me. anyway i had to make my way around, and since the exclude ids is not working bu the filter is perfectly does so i will use the filter parameter to only show the uninvited friends like this.

<?php 

 //get the current user id.
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2); 
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);

//get the already invited friends from the database based on $data["user_id"].
    $SQL = mysqli_query($con,"select the invited users ids from the DB"); 
     $exclude_ids = $data["user_id"]; //$data["user_id"] ia my facebook id i added it to the excluded ids because i will not use app_non_users in the filter
    while($row = mysqli_fetch_assoc($SQL))
    {
        $exclude_ids = $exclude_ids . "," . $row['invto']  ;
    }
    mysqli_free_result($SQL);
    mysqli_close($con);

//get my friends.
require("php-sdk/src/facebook.php");
     $facebook = new Facebook(array('appId'  => 'APP_ID','secret' => 'APP_SECRET','cookie' => true,));

    $fbme = $facebook->api('/me/friends');
    $datas = $fbme['data'];

 foreach($datas as $x)
 {
     $arymyfriends[] = $x['id'];
 }

 //compare my friends to the invited friends and get the unmatched.
 $aryexcluded = explode(",",$exclude_ids);
 $aryresults = array_diff($arymyfriends,$aryexcluded);
 $exclude_ids = implode(",",$aryresults );


 //show the invitation page
     $app_id = "12345678912358";
     $canvas_page = "http://apps.facebook.com/appname/";
     $message = "come join this cool app.";
     $filters = array(array('name' => 'Best friends','user_ids' => $exclude_ids));
     $requests_url = "https://www.facebook.com/dialog/apprequests?app_id=" . $app_id 
     . "&redirect_uri=" . urlencode($canvas_page) 
     . "&message=" . $message 
     . "&filters=" . json_encode($filters) 
     . "&max_recipients=25";

     if (empty($_REQUEST["request_ids"])) {
        echo("<script> top.location.href='" . $requests_url . "'</script>");

     }

i know it is not the best solution but it works...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜