这是我的邀请码:
<?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 this 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;
&GT;
除了邀请的朋友之外,每件事情都很顺利。 这有什么问题?
答案 0 :(得分:0)
关于构建逗号分隔字符串的注释:如果先将它们放入数组中,它会变得更容易。
$excludeIdArr=[];
$excludeIdStr="";
while($row = mysqli_fetch_assoc($SQL))
{
$excludeIdArr[]=$row['inviteduserid'];
}
$excludeIdStr = implode(",",$excludeIdsArr);
您在ID列表的开头有一个额外的逗号...
此外...... The documentation of the requests dialog表示exclude_ids
参数采用数组。
exclude_ids
将从对话框中排除的用户ID数组...
答案 1 :(得分:0)
感谢Lix,但我不知道为什么它仍然不适合我。 无论如何我必须绕道而行,因为排除ID不起作用,过滤器是完全可行的,所以我将使用过滤器参数只显示这样的未经邀请的朋友。
<?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>");
}
我知道这不是最好的解决方案,但它有效......