0

还是没有办法邀请所有的群成员参加一个群事件?我可以通过 api 创建小组活动,但不会邀请成员参加新活动。如果我通过 facebook 网站创建活动,我可以选择“邀请所有群组成员”。我似乎找不到任何方法来通过 api 重现该功能。

4

1 回答 1

0

由于无法直接通过图形 api 执行此操作,我最终制作了自己的 php w/mysql 解决方案。基本上,我会为我组的所有成员制作一张表格,然后检查他们是否已被邀请参加我组的所有活动。这种强制方法的好处是,如果在创建活动后有新成员加入,他们将被邀请参加所有未来的活动。

facebook 不会告诉您每个时间段您可以从 api 邀请多少成员并且不会被标记为垃圾邮件

转储组成员的代码:

function UpdateFacebookMemberDB($verbatim = FALSE)
{
    global  $access_token, $groupID;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$groupID.'/members?access_token='.$access_token);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_USERAGENT , 'facebook-php-3.2');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
    $return = curl_exec($ch);
    curl_close ($ch);
    $decoded = json_decode($return, true);
    $decoded = $decoded['data'];
    Sql_Connect();
    if(!Sql_Query("DELETE FROM `Facebook_User`;"))
    {
        echo "Could not empty the `Facebook_User` table.<br>\n";
        return FALSE;
    }
    foreach ($decoded as $value)
    {
        $query="INSERT INTO `Facebook_User` (`Name`, `FID`) VALUES ('".Sql_CleanInput($value['name'])."', '".Sql_CleanInput($value['id'])."');";
        if(Sql_Query($query))
        {
            if($verbatim)
                echo $value['name']." was added to the database.<br>";
        }
        else if($verbatim)
                echo $value['name']." was <b>NOT</b> added to the database.<br>";
    }

    if(!Sql_Query("DELETE FROM `Facebook_Event`;"))
    {
        echo "Could not empty the `Facebook_Event` table.<br>\n";
        return FALSE;
    }
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$groupID.'/events?fields=start_time&since=now&access_token='.$access_token);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_USERAGENT , 'facebook-php-3.2');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
    $return = curl_exec($ch);
    curl_close ($ch);
    $decoded = json_decode($return, true);
    $decoded = $decoded['data'];
    foreach ($decoded as $value)
    {
        $eid = $value['id'];
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$eid.'/invited?access_token='.$access_token);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_USERAGENT , 'facebook-php-3.2');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
        $return = curl_exec($ch);
        curl_close ($ch);
        $decod = json_decode($return, true);
        $decod = $decod['data'];
        foreach ($decod as $val)
        {
            $query="INSERT INTO `Facebook_Event` (`EventID`, `UserID`) VALUES ('".$eid."', '".$val['id']."');";
            if(Sql_Query($query))
            {
                if($verbatim)
                echo $val['name']." was added to the database.<br>";
            }
            else if($verbatim)
            echo $val['name']." was <b>NOT</b> added to the database.<br>";
        }
    }
    Sql_Disconnect();
}

检查/邀请成员的代码:

function InviteClubToEvent)
{
    global  $access_token, $groupID;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$groupID.'/events?fields=start_time&since=now&access_token='.$access_token);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_USERAGENT , 'facebook-php-3.2');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
    $return = curl_exec($ch);
    curl_close ($ch);
    $decoded = json_decode($return, true);
    $decoded = $decoded['data'];
    $invite=0;
    for($x=count($decoded)-1;$x>=0;$x--)
    {
        $eventid = $decoded[$x]['id'];
        Sql_Connect();
        $query="SELECT * from `Facebook_User` ORDER BY `FID` ASC;";
        $qresult=Sql_Query($query);

        $data = array( 'access_token' => $access_token);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_USERAGENT , 'facebook-php-3.2');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
        for($i=0;$i<Sql_Num_Rows($qresult);$i++)
        {
            $subquery="SELECT * from Facebook_Event WHERE `UserID` ='".Sql_Result($qresult,$i,"FID")."' AND `EventID` ='".$eventid."'LIMIT 1;";
            if(Sql_Num_Rows(Sql_Query($subquery))==0)
            {
                $invite++;
                curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$eventid.'/invited/'.Sql_Result($qresult,$i,"FID"));
                $return = curl_exec($ch);
                if($return == "true")
                {
                    echo "$invite) ".Sql_Result($qresult,$i,"Name") . " has been invited to $eventid!<br>";
                    Sql_Query("INSERT INTO `sdbmwcca_main`.`Facebook_Event` (`EventID`, `UserID`) VALUES ('".$eventid."', '".Sql_Result($qresult,$i,"FID")."');");
                } else
                {
                    echo "<hr><b>$invite) ".Sql_Result($qresult,$i,"Name") . " was not invited because: " . $return . "</b><hr>";
                    curl_close($ch);
                    Sql_Disconnect();
                    die();
                }
            }
            if($invite > ##some spam limit##)
            {
                $x = 0;
                break;
            }
        }
        curl_close ($ch);
        Sql_Disconnect();
    }
}
于 2014-01-19T05:16:24.410 回答