1
我想邀請頁面的所有球迷使用批處理API Facebook的事件。這是我第一次使用這個API,並且此時我沒有任何東西可以測試這部分代碼......有人能告訴我如何在不使用真實頁面的情況下測試,真正的粉絲......還是告訴我是否它看起來正確?批量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++;
}
}
}
實際上正在使用Facebook不允許邀請球迷,唯一的朋友是球迷太...悲傷...但感謝您的回答! –