Question

I want to build a FB app which posts messages to the walls of those registered for the app. There are two setups:

  1. One message to many people (1-many, could occur few times a day)
  2. Many user-specific massages (1-1, but many of them, could occur few times a day for each user)

All in all; one user could get a few different updates on his wall per day, but it could affect many users (that's pretty much the whole point of my idea) Into what extend is Facebook going to allow me to do this, and won't think I'll be spamming.

PS: I've come along this post, which seems to have remained unsolved...: Post on Multiple Friend's Wall

And this post, which doesn't make it clear for me whether my idea is something I should start or not ;) Graph API post to wall limitation

Was it helpful?

Solution

You can use Facebook batch API to do what you intent.

You can get more information on Facebook batch request at: http://25labs.com/tutorial-post-to-multiple-facebook-wall-or-timeline-in-one-go-using-graph-api-batch-request/

$batchPost[] = array(
    'method' => 'POST',
    'relative_url' => "/{ID1}/feed?access_token={ACCESS_TOKEN_FOR_ID1}",
    'body' => http_build_query($body) );
$batchPost[] = array(
    'method' => 'POST',
    'relative_url' => "/{ID2}/feed?access_token={ACCESS_TOKEN_FOR_ID2}",
    'body' => http_build_query($body) );
$batchPost[] = array(
    'method' => 'POST',
    'relative_url' => "/{ID3}/feed?access_token={ACCESS_TOKEN_FOR_ID3}",
    'body' => http_build_query($body) );

$multiPostResponse = $facebook->api('?batch='.urlencode(json_encode($batchPost)), 'POST');

OTHER TIPS

I developed an app in my website http://www.cefozyt.com which can post links, message etc. to multiple facebook users wall & groups. I used :-

if($user){ // Proceed knowing you have a logged in user who has a valid session.

//========= Batch requests over the Facebook Graph API using the PHP-SDK ======== // Save your method calls into an array $queries = array( array('method' => 'GET', 'relative_url' => '/'.$user), array('method' => 'GET', 'relative_url' => '/'.$user.'/friends'), 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);

//========= Batch requests over the Facebook Graph API using the PHP-SDK ends =====

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;
    }
}

} ?>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top