2011-09-16 8 views
0

これは私の招待コードです:なぜ、exclude_idsパラメータがFacebookのアプリケーションの招待状で機能していないのですか?

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

>

すべてのものは、それが招待友人を除外されていない以外は非常にうまく機能しています?。 これは何が問題なのですか?

答えて

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>"); 

    } 

私はそれが最善の解決策ではありません知っているが、それは動作します...

0

コンマで区切られた文字列を作成する際の注意:最初に配列に入れた方がずっと簡単です。

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

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

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

あなたは...また

のidのリストの先頭に余分なコンマを持っていた... The documentation of the requests dialogexclude_idsパラメータは配列を受け取り言います。

exclude_ids
ダイアログから除外されたユーザIDの配列...