我有一个代码可以自动邀请用户参加我们在接受应用程序时创建的事件,但它会自动邀请所有朋友,是否有可能限制其邀请的朋友数量,而不是邀请他们每次查看应用程序时,将其限制为只是初次接受应用程序?
代码:
$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/javascript'>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; }
}
}
答案 0 :(得分:0)
我不认为您可以在不违反Facebook政策的情况下自动邀请用户的朋友: http://developers.facebook.com/policy/
让用户通过一个明显标签的按钮主动发出邀请,你就可以了。