I'm in the middle of building a Facebook App, I want the app to publish a predefined message to:
1) A user's news feed ( i.e. any user who has used the app )
2) If possible to the user's friend's news feeds or even their wall.
At the moment, I only have it posting to a user's wall, using the following code:
if(isset($_POST['mapp_message'])){
try {
$facebook->api('/me/feed', 'POST', array(
'access_token' => $facebook->getAccessToken(),
'message' => $_POST['mapp_message'],
'name' => "This is the title of my post",
'description' => "This is the body of the post with lots of text in it",
'link' => 'http://www.mysite.com',
'picture'=>"http://lipsum.com/images/lipsum07.gif",
'privacy' => array('value' => 'EVERYONE')
));
$sent = true;
} catch (FacebookApiException $e) {
//do something about it
}
}
Note: I've just discovered that their is a difference between the users wall and news feed.
I've been googling this for a few hours, but I haven't been able to figure it out. So any help appreciated.
Regards
UPDATE
Ok, I made a bit of progress. I managed to get it posting on user's friend's walls ( i.e. friends of people who have used the app ). The code is as follows:
try {
$userData = $facebook->api('/me');
} catch (FacebookApiException $e) {
//do something about it
}
try {
$friendsTmp = $facebook->api('/' . $userData['id'] . '/friends');
shuffle($friendsTmp['data']);
array_splice($friendsTmp['data'], 5);
$friends = $friendsTmp['data'];
} catch (FacebookApiException $e) {
//do something about it
}
This bit of code randomly selects 5 friends of the user who has used the app and to post to their walls the code is as follows:
foreach($friends as $k => $i){
$facebook->api('/'.$i['id'].'/feed', 'POST', array(
'access_token' => $facebook->getAccessToken(),
'message' => $_POST['mapp_message'],
'name' => "This is the title of my post",
'description' => "This is the body of the post with lots of text in it",
'link' => 'http://www.mysite.com',
'picture'=>"http://lipsum.com/images/lipsum07.gif"
//'privacy' => array('value' => 'EVERYONE')
));
}
But I still would prefer if I could get this posted to the News Feeds instead.