Author Topic: Facebook Graph API - How to post on friend's wall (Not on Feed)  (Read 4346 times)

kathir

  • Administrator
  • Sr. Member
  • *****
  • Posts: 283
Facebook Graph API - How to post on friend's wall (Not on Feed)
« on: January 13, 2012, 01:00:57 am »
Facebook does not allow to post on your friend's wall in bulk. You may post to your 5 or 10 friends at a time or per day. No idea on the limit, but it is very less. The limit may go up based on your app interaction and time.

However the coding can be done to post on all of your friend's wall from your app. After 5 - 10 tries, Facebook would start giving back error message - the limit has reached. NOTE: you can not use an APP to post a message on all of your friend's wall in one shot as it is considered as SPAM.

Here is the PHP code to post on all of your friend's wall. First you need to download php sdk.

For Complete Reference: http://www.softwareandfinance.com/apps/facebook/index.html

Code: (php)
//Source Code Listing

include_once 'facebook.php';

$facebook = new Facebook(array(
    'appId' => 'YOUR_APP_ID',
    'secret' => 'YOUR_SECRET_KEY',
    'cookie' => true,
    'domain' => 'www.softwareandfinance.com'
));

$app_name = "Broadcast to Friends";
$app_url = "http://apps.facebook.com/your_app_name/";

$user_id = $facebook->getUser();

if (!$user_id) {    
    $url = $facebook->getLoginUrl(array(
    'canvas' => 1,
    'fbconnect' => 0

    ));

} else
{
    try {
        $permissions = $facebook->api("/me/permissions");
        if(! array_key_exists('publish_stream', $permissions['data'][0]) ) { 
            header( "Location: " . $facebook->getLoginUrl(array("scope" => "publish_stream")) );
        } 

        $permissions = $facebook->api("/me/permissions");

        if( array_key_exists('publish_stream', $permissions['data'][0]) ) {
            $friends = array();
            $_friends = $facebook->api("/me/friends"); 

            if (is_array($_friends) && count($_friends)) {
                foreach ($_friends as $friend) { 
                    $friends[] = $friend['uid'];
                    $location = "/" . friend[uid] . "/feed";
                    $post_id = $facebook->api($location, 'post', array('message'=>'Hello World!'));
                    echo "posted on friend's wall" . $post_id;
                }
            }
        }

    } 
    catch (FacebookApiException $e) 
    {
        echo "Error: Unable to post on your friend's wall";

    }
}

 


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1