I know the basics of how to post a status update, link, etc. from within a Facebook application, thanks to http://developers.facebook.com/docs/guides/canvas/, but I can't figure out whether it's possible to limit the post's visibility to a certain preset list of friends of the user authorizing the post (since the documentation on Facebook's site isn't exactly the best).
Is it possible to post to the user's wall from within my application so that it's only visible to a pre-selected list of friends? I'm mimicking the functionality of Google Plus's "Circles" feature, where the user can have various groups of friends and post to only those group lists.
This is definitely possible. Please read the Post documentation, especially the privacy parameter:
object containing the
valuefield and optionalfriends,networks,allowanddenyfields.The
valuefield may specify one of the following strings:EVERYONE,ALL_FRIENDS,NETWORKS_FRIENDS,FRIENDS_OF_FRIENDS,CUSTOM.The
friendsfield must be specified ifvalueis set toCUSTOMand contain one of the following strings:EVERYONE,NETWORKS_FRIENDS(when the object can be seen by networks and friends),FRIENDS_OF_FRIENDS,ALL_FRIENDS,SOME_FRIENDS,SELF, orNO_FRIENDS(when the object can be seen by a network only).The
networksfield may contain a comma-separated list of network IDs that can see the object, or 1 for all of a user's network.The
allowfield must be specified when thefriendsvalue is set toSOME_FRIENDSand must specify a comma-separated list of user IDs and friend list IDs that 'can' see the post.The
denyfield may be specified if thefriendsfield is set toSOME_FRIENDSand must specify a comma-separated list of user IDs and friend list IDs that 'cannot' see the post.Note: This privacy setting only applies to posts to the current or specified user's own Wall. Facebook ignores this setting for targeted Wall posts (when the user is writing on the Wall of a friend, Page, event, group connected to the user). Consistent with behavior on Facebook, all targeted posts are viewable by anyone who can see the target's Wall.
Privacy Policy: Any non-default privacy setting must be intentionally chosen by the user
A small example using the PHP-SDK:
<?php
require '../src/311/facebook.php';
$facebook = new Facebook(array(
'appId' => 'APP_ID',
'secret' => 'APP_SECRET',
));
$user = $facebook->getUser();
if ($user) {
try {
$privacy = array(
'value' => 'CUSTOM',
'friends' => 'SOME_FRIENDS',
'allow' => 'XXXXXXX,YYYYYYY' // Change this to your friends ids
);
$params = array();
$params['privacy'] = json_encode($privacy);
$params['message'] = "Special for TWO friends";
$post_id = $facebook->api('/me/feed', 'POST', $params);
var_dump($post_id);
} catch (FacebookApiException $e) {
print_r($e);
$user = null;
}
}
?>
What I've done here:
publish_stream permission)
Please note that you have a lot of options here, you can deny specific user, allow networks, allow Friends list...it's really up to you to customize the value, friends, allow, deny and networks fields.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With