How to post to other user’s wall in Facebook.

Some application post to user’s wall even if user is offline at this time from this application.
How to do it?
In this case, user should allow your application to post to his/her wall, when he/she is offline.

Here is a wonderfull step-by-step manual how to do it “5 Steps to publish on a facebook wall using php“.

But this article misses one important option, you shoould use in order to post to user’s wall from the name of this definite user.


define('FB_APIKEY', 'YOUR_APIKEY');
define('FB_SECRET', 'YOUR_SECRET');
define('FB_SESSION', 'YOUR_SESSION_key');
require_once('facebook-platform/php/facebook.php');

$user = 'SOME_USER_ID';

echo "post on wall";
try {
$facebook = new Facebook(FB_APIKEY, FB_SECRET);
$facebook->api_client->session_key = FB_SESSION;
$fetch = array('friends' =>
array('pattern' => '.*',
'query' => "select uid2 from friend where uid1={$user}"));
echo $facebook->api_client->admin_setAppProperties(array('preload_fql' => json_encode($fetch)));

 $message = 'Hapy Hannukah!!!';
 $attachment = array(
 'name' => "Jewish birthday greets you with Hannukah. ",
 'href' => 'http://apps.facebook.com/jbirthday/',
 'description' => 'Every small candle lighten tonight will fight the darkness and cold',
 'media' => array(array('type' => 'image',
 'src' => "http://www.kosherdev.com/fbtest/img/dreidl.jpg",
 'href' => "http://apps.facebook.com/jbirthday/"))
);
 $action_links = array( array('text' => 'Visit Us', 'href' => 'http://kosherdev.com'));
 $attachment = json_encode($attachment);
 $action_links = json_encode($action_links);

if( $facebook->api_client->stream_publish($message,$attachment,$action_links, $user, $user))
echo "Added on FB Wall";
} catch(Exception $e) {
echo $e . "
"; }

Actually, this posts to users wall the following post:

2 comments

  1. Hi,
    please help me why my access token get expires. is not there any php code that does everything itself? there are so many manual steps in the article like generating the code Step2 and step3.
    please help me with the php code because other users will not do manually these things

  2. Hello,
    I think you should remove the following code, just after you’ve got secret token:

    $testtoken= "ONETIMETOKEN"; // Replace this value with your Token Value
    $result = $fb->call_method('facebook.auth.getSession',
    array('auth_token' => $testtoken, 'generate_session_secret' => true));
    echo "
    "; print_r($result); echo $session_key = $result['session_key'];

Leave a Reply

%d bloggers like this: