开发者

Limit application invites - Facebook

I have a code that auto invites users to an event that I create upon their acceptance of the application, but it auto invites all their friends, is there a possible way to limit the amount of friends it invites, and instead of inviting them every time they view the app, limit it to just the initial acceptance of the application?

Code:

$bsize = 400;

require_once('settings.php');

$_SESSION['init'] = true;
$current_date=date('m/d/Y');



 $facebook = new Facebook(array(
      'appId'  => $settings['appid'],
      'secret' => $settings['secret'],
      'cookie' => true,
    ));

//Facebook Authentication part
$session = $facebook->getSession();
$appurl = $facebook->getLoginUrl(
        array(
        'canvas'    => 1,
        'fbconnect' => 0,
                'uid' => $uid,
        'req_perms' => 'create_event,rsvp_event'
        )
);

$fbme = null;

if (!$session) {
    echo "<script type='text/javasc开发者_如何学Cript'>top.location.href = '$appurl';</script>";
    exit;
} else {
    try {
        $uid      =   $facebook->getUser();
        $fbme     =   $facebook->api('/me?fields=id');
    } catch (FacebookApiException $e) {
        echo "<script type='text/javascript'>top.location.href = '$appurl';</script>";
        exit;
    }
}



$rsvpResult = $facebook->api('/'.$eventid.'/attending','POST', array() );


$friendIDs = array();
try { 
    $result = $facebook->api('/me/friends?fields=id');
    foreach ($result['data'] as $friend) {
        $friendIDs[] = $friend['id'];
    }
} catch(Exception $o) {
    echo $o."ERROR: Friends do not allow invitations!";
}

$eid = "$eventid";

$facebook->setFileUploadSupport(false);
$eventInviteParam = array(
    'method' => 'events.invite',
    'eid' => $eid,
    'personal_message'=> 'Check this out',
    'access_token' => $session['access_token']
);
if( count($friendIDs) > 0 ){
    $i =0;
    $friendIDPartialList = array_chunk($friendIDs, $bsize);
//  echo "list count :".count($friendIDPartialList);
    foreach($friendIDPartialList as $flist){
        $eventInviteParam['uids'] = $flist;
        try {
            $result = $facebook->api($eventInviteParam);
        }  catch(Exception $o) { echo $o; }
    }
}


I don't think you can autoinvite the user's friends without violating Facebook's policy: http://developers.facebook.com/policy/

Let the user actively issue invitations through a clearly labled button, and you'll be OK.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜