【问题标题】:Batch API, inviting friends批量API,邀请好友
【发布时间】:2014-01-20 07:37:46
【问题描述】:

我正在尝试使用批处理 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++;
       }
   }
}

【问题讨论】:

    标签: events facebook-page facebook-batch-request


    【解决方案1】:

    您的代码看起来不错,但不要忘记您可能需要将访问令牌添加到批处理请求中

    喜欢:

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

    为了进行测试,您可能需要创建一个添加了几个朋友的新页面并对其进行测试。

    还要记住你需要处理响应,批处理请求将响应一个与批处理数组长度相同的数组,并且每个对象可能是不同的代码,如果是发送则为真。

    您也可以在Graph Explorer (clic here) 中尝试您的 FQL 代码

    看起来不错,但它显示了一个额外的结果。

    【讨论】:

    • 事实上 facebook facebook 不允许邀请粉丝,只能邀请那些也是粉丝的朋友...伤心...但感谢您的回答!
    猜你喜欢
    • 2011-10-27
    • 1970-01-01
    • 1970-01-01
    • 2012-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多