Is there a way to post a message to a Facebook group's feed? - facebook

I'm working on a Facebook app that uses Facebook groups, and I'd like to open up a Feed dialog to let the user post a notice to the group's feed. I have a user who is in the group and I've got the relevant permissions as well.
I've tried passing the group's Facebook id in the https://developers.facebook.com/docs/reference/dialogs/feed/ feed dialog, but get a Facebook error. There doesn't appear to be a programmatic way to do it either: the group's feed (described at https://developers.facebook.com/docs/reference/api/group/) isn't documented to accept POSTs either. Is there a way to post a message to the group using the Graph API or one of the other API methods?

I just made a test and it's working as any other wall.
I made a POST to 'GROUP_ID/feed' with a message variable with a value and it worked. I logged into the app as the group owner.
Using facebook php-sdk:
$facebook->api('GROUP_ID/feed', 'POST', array(
'message' => 'Testing...'
)));

I would suggest to use javascript instead as it wont cause post back of our website.
Check out my application to see if that what you want -> WooTube
function Promote() {
var lnk =
'http://www.wootube.woolei.com?v=<?php echo $_GET["id"] ?>';
FB.login(function(response) {
if (response.authResponse) {
//Post To WooTube Group
FB.api('/271691796276524/feed', 'post', {
message: lnk,
link: lnk,
},
function(response) {
if (!response || response.error) {
//alert('You have to join the group first!');
} else {
//alert("Successfully Posted to WooTube Group!");
}
});
//Post to Wootube Page
FB.api('/173724382762792/feed', 'post', {
message: lnk,
link: lnk
},
function(response) {
if (!response || response.error) {
//alert('You have to like http://www.facebook.com/WooTubes first!');
} else {
//alert("Successfully Posted to WooTube Page!");
}
});
} else {
alert('Not logged in');
}
}, {
scope: 'publish_stream'
});
}

Related

Facebook Post through Graph API with access token

I am developing a facebook app where I need impersonation of users, so there is an option when you use facebook for "Use Facebook As", i need to implement the same in my app.
I see the access tokens retrieved for the pages I own, but I don't understand how to use this with the following graph api to post
var body = 'Reading JS SDK documentation';
FB.api('/me/feed', 'post', { message: body }, function (response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
so my question is how do I set the access token for the api in this case??
I Hope, am clear with my question
Add it with the parameters. Change this line
FB.api('/me/feed', 'post', { message: body }, function (response) {
to...
var my_token = "the access token value";
FB.api('/me/feed', 'post', { message: body, access_token : my_token }, function (response) {

Post a public message in Facebook with FB.api

I have tried to post a message on my wall using FB.api(). I posted it successfully but it's showing only for me. I want to make this post public.
In app Configuring permissions i set "Default Activity Privacy" value Public but still message posting private.
I tried to do it by following code:
FB.login(function (response) {
if (response.authResponse) {
var privacy = { 'value': 'EVERYONE' };
var txt = 'my post to test feed post using api';
FB.api('me/feed', 'post', { message: txt, privacy: privacy }, function (response) {
if (!response || response.error) {
alert(JSON.stringify(response.error));
} else {
alert('Post ID: ' + response.id);
}
});
}
}, { scope: 'email,user_likes,publish_actions,publish_stream,read_stream' });
Please check my code.
As said in reference 'privacy' field value should be string.
Try to pass "{ 'value': 'EVERYONE' }" as string, not an object.

Facebook API feed dialog - prevent unnecessary click

hi,
Using Facebook's API it's possible to prompt a user to post to his/her wall using the feed dialog. However, using the javascript SDK, this requires two clicks: one on the button which brings up the dialog, the other on the "Share" button within the dialog.
Is it possible to get rid of one of these clicks? I thought of two approaches:
Embedding the dialog within an iframe, as Facebook provides a URL for a full page dialog. That will require the user to click only on the "Share" button. Apparently Facebook blocks that option.
Using an access token and display=iframe, but I want to avoid the user having to authorize my application.
Any ideas?
i would suggest you to use fb.api instead.
function PostToMyWall(){
FB.login(function(response)
{
if (response.authResponse)
{
//Post to my wall
FB.api('/me/feed', 'post', {
message: lnk,link: lnk
},
function(response) {
if (!response || response.error) {
// //alert('Error occured');
} else {
// //alert("Successfully Posted to My Wall!");
}
});}else
{
alert('Not logged in');
}}, { scope : 'publish_stream' });
}
My application got a similar function, check it out at www.wootube.woolei.com - "Post to WooTube Page and Group"
or popup when the page using jquery
$(document).ready(function() { FB.ui({method: 'feed',
name: mdtxt,
link: lnk,
picture: hackImageUrl(img,fld),
caption: '<?php echo $clickme; ?>',
description: '<?php echo $app_desc; ?>'
},
function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert("Successfully Posted to Group");
}
});});

Cakephp Facebook Plugin - Sharing through an action

I am using Nick Baker's (webtechnick) CakePHP / Facebook plugin which is awesome and works great, however I have a question that I can't seem to even come close to answer for.
How would I bypass the use of a share button and share directly through an action?
For instance, I make a post through my site and the post adds to the DB as it should, it also shoots a post to the logged in users Twitter account through the action. How can I also have this action handle sharing it to my FB account (connection has already been made).? I tried the first thing I think anyone would obviously try $this->Facebook->share() directly in the action, too no avail...
Any thoughts or solutions would be of great help...
UPDATE AFTER ANSWER
Thx for the help spooney. I voted your answer up because you are 100% spot on from what I can tell. I am loading the JS SDK.
function init($options = null, $reload = true) {
if (empty($options)) {
$options = array();
}
if ($appId = FacebookInfo::getConfig('appId')) {
$session = json_encode($this->Session->read('FB.Session'));
if ($reload) {
$callback = "FB.Event.subscribe('auth.login',function(){window.location.reload()});";
} else {
$callback = "if(typeof(facebookReady)=='function'){facebookReady()}";
}
$callback .= "FB.Event.subscribe('auth.logout',function() {window.location = '/bastards/users/logout'});";
$init = '<div id="fb-root"></div>';
$init .= $this->Html->scriptBlock(
<<<JS
window.fbAsyncInit = function() {
FB.init({
appId : '{$appId}',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
oauth : true // use Oauth
});
{$callback}
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/{$this->locale}/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
JS
, $options);
return $init;
} else {
return "<span class='error'>No Facebook configuration detected. Please add the facebook configuration file to your config folder.</span>";
}
}
I have no problem pulling in the user information and working with all that. I have accomplished posting to FB from my site, but it was only through a link, using FB.ui...
<br><font style="color:#FFF; text-decoration:none;padding-left:27px;">post to wall</font><br>
<script>
function publishStory() {
FB.ui({
method: 'feed',
name: 'message name',
caption: 'message caption ',
description: 'description goes here',
link: 'the url current page',
picture: 'if you want to add an image'
},
function(response) {
console.log('publishStory response: ', response);
});
return false;
}
</script>
I have tried replacing the code above with...
<br><font style="color:#FFF; text-decoration:none;padding-left:27px;">post to wall</font><br>
<script>
function publishStory() {
var body = 'Reading JS SDK documentation';
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
}
</script>
But it errors everytime.
I should also throw in there that the post on the users FB wall isn't really coming from the site persay, it's a post from the user on their own wall basically stating, "I made a post on ladala.com, you should go check it out at ."
So now I'm at the point that I need to figure out how to run FB.ui through the action that submits the post.
Based on our conversation, I figured I would just put a more complete description in an answer.
You can fire a share call using the JavaScript SDK.
First, you would need to load the JavaScript SDK as described in the Loading section of https://developers.facebook.com/docs/reference/javascript/.
Once loaded into your page, the two calls you want to look at are FB.getLoginStatus, and FB.api. FB.getLoginStatus will give you back a response telling you if the user is logged in to facebook, and if they have approved your application. This link will describe the functionality of getLoginStatus, but in short, you need to check for response.connected(and then possibly do another call to confirm a user's permissions, if required).
If the user is logged in and has approved your app, you can then attempt to make an API call using FB.api. Keep in mind to do this, you will likely need the user to have allowed the publish_stream permission.
Your code would look something like this:
//Do FB initialization
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
//Post was successful
}
});
}
});
This can be triggered any way you want. On page load, on click, on completion of some other event, etc.
Keep in mind this is just one way to implement this. Also, if you are trying to share something with your FB application, and it is not working, you should confirm that you have all the permissions required to do so.

Facebook Javascript SDK: Tag another user in my wall post?

We are using the Facebook Javascript SDK to allow users to post content to their wall. In the message that gets posted, is it possible to tag another user, similar to how you can when typing a post on facebook.com? (using something like #person)
We are using:
FB.api('/me/feed', 'post', { message: 'This post came from a test. #someuser'}, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
The end result would then be a post that tagged the #someuser user.
The Facebook API doesn't currently support tagging of users like this. That functionality is limited to the actual site itself.