2012-10-19 4 views
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++; 
     } 
    } 
} 

답변

0

코드는 괜찮아 보이지만, 당신이

같은 일괄 요청에 액세스 토큰을 추가해야 할 수 있습니다 잊지 말아 : 새를 만들 수 있습니다

$params['access_token']=[USER_ACCESS_TOKEN]; 

$ret_val = $facebookObj->api('/?batch='.json_encode($queries[$a]), 'POST', $params); 

그리고 테스트를 위해 몇 명의 친구가 추가 된 페이지를 테스트하고 테스트합니다.

응답을 처리해야한다는 것을 기억하십시오. 일괄 처리 배열과 길이가 같고 각 객체가 다른 코드 일 수 있습니다 (전송 된 경우 true).

또한 당신이 Graph Explorer (clic here)

에 FQL 코드를 시도 할 수 있습니다 확인을 보인다, 그러나 그것은 extrange 결과를 보여줍니다.

+0

실제로 페이스 북의 페이스 북은 팬을 초대하는 것을 허용하지 않고, 너무 슬퍼하는 팬만 슬퍼하지만 대답에 감사드립니다! –