我開發我的網站http://www.cefozyt.com一個應用程序,它可以發佈鏈接,郵件等多個Facebook用戶牆&組。我使用: -
if($ user){ //繼續知道您有一個擁有有效會話的登錄用戶。
// =========使用PHP-SDK在Facebook Graph API上的批量請求======== //將您的方法調用保存到數組中 $ queries = array ('method'=>'GET','relative_url'=>'/'.$user), array('method'=>'GET','relative_url'=>'/'。用戶。 ''/'朋友'), array('method'=>'GET','relative_url'=>'/'.$user.'/groups'), array('method'=>'GET','relative_url '=>'/'.$user.'/likes'), );
// POST your queries to the batch endpoint on the graph.
try{
$batchResponse = $facebook->api('?batch='.json_encode($queries), 'POST');
}catch(Exception $o){
error_log($o);
}
//Return values are indexed in order of the original array, content is in ['body'] as a JSON
//string. Decode for use as a PHP array.
$user_info = json_decode($batchResponse[0]['body'], TRUE);
$friends_list = json_decode($batchResponse[1]['body'], TRUE);
$groups = json_decode($batchResponse[2]['body'], TRUE);
$pages = json_decode($batchResponse[3]['body'], TRUE);
// =========過使用PHP-SDK Facebook的圖形API批次請求結束=====
if(isset($_POST['submit_x'])){
if($_POST['message'] || $_POST['link'] || $_POST['picture']) {
$body = array(
'message' => $_POST['message'],
'link' => $_POST['link'],
'picture' => $_POST['picture'],
'name' => $_POST['name'],
'caption' => $_POST['caption'],
'description' => $_POST['description'],
);
$batchPost=array();
$i=1;
$flag=1;
foreach($_POST as $key => $value) {
if(strpos($key,"id_") === 0) {
$batchPost[] = array('method' => 'POST', 'relative_url' => "/$value/feed", 'body' => http_build_query($body));
if($i++ == 50) {
try{
$multiPostResponse = $facebook->api('?batch='.urlencode(json_encode($batchPost)), 'POST');
}catch(FacebookApiException $e){
error_log($e);
echo("Batch Post Failed");
}
$flag=0;
unset($batchPost);
$i=1;
}
}
}
if(isset($batchPost) && count($batchPost) > 0) {
try{
$multiPostResponse = $facebook->api('?batch='.urlencode(json_encode($batchPost)), 'POST');
}catch(FacebookApiException $e){
error_log($e);
echo("Batch Post Failed");
}
$flag=0;
}
}
else {
$flag=2;
}
}
} ?>
我以前沒有見過批量APi,很棒的功能!根據[link](http://developers.facebook.com/docs/reference/api/batch/),它的限制目前是50.假設我有1.000個不同的用戶,那麼我必須將這個帖子分散到20個請求(儘可能短的「間隔」)。這會成爲一個問題嗎? – Planetcrypton 2012-03-19 20:59:53
我不認爲這會是一個問題..您可以使用20個請求發佈到1000個用戶..但始終記住不要垃圾郵件用戶..在我提到的博客文章中,你可以找到更多關於問題。實際上,該帖子中的腳本會執行多個批量API調用,以發佈給50多個朋友。 – 2012-03-20 02:16:21
就我而言,所有的用戶都沒有(nescasarily)相互關聯。我只需要發佈一堆不同的ID。根據[這個論壇帖子](http://forum.developers.facebook.net/viewtopic.php?id = 56950),您可以在600秒內撥打600個電話(因爲他們在2010/2011年回覆)。所以這意味着理論上可以在10分鐘內製作50 * 600 = 30000個帖子......天哪! – Planetcrypton 2012-03-20 08:32:34