我正在尝试使用批处理 API 邀请页面的所有粉丝参加 facebook 活动。这是我第一次使用这个API,此时我没有什么可以测试这部分代码......有人可以告诉我如何在不使用真实页面的情况下进行测试,有真正的粉丝......或者告诉我是否它看起来正确吗?
//Getting all the likers of the page
$result = $facebookObj->api(array(
'method' => 'fql.query',
'query' => 'select uid,name from user where uid in ( select uid from page_fan where uid in (select uid2 from friend where uid1 = me()) and page_id = '.$fbPage.')'
));
//If liker are more than 50 we use batch request
if($numLikers >50){
// split array into several part of 50 users accounts
$splitLikers = array_chunk($result, 50);
// count how many arrays are generated by the array_chunk
$countSplit = count($splitLikers);
//Start a loop through the numbers of groups of 50 users (or less if last group contains less than 50 users
for($a=0; $a<$countSplit; $a++){
//Second loop to go through the 50 likers in one group
for($b=0; $b<count($splitLikers[$a]); $b++){
// construct an array containing the whole group
$queries[$a] = array('method' => 'POST', 'relative_url' => $event_fbID . "/invited/" . $splitLikers[$a][$b]['uid']);
}
//Send POST batch request with the array above
$ret_val = $facebookObj->api('/?batch='.json_encode($queries[$a]), 'POST');
}
}else{
foreach ($result as $value) {
$ret_val = $facebookObj->api($event_fbID . "/invited/" . $value['uid'],'POST');
if($ret_val) {
// Success
$numInvited++;
}
}
}