Posting in wall with not logged user (using offline token) - facebook

I need to post on the wall of a user as if it were itself (offline token), but when logged in with another user. Example:
I login with user X. In some moment I want to post on the wall of the user Y as if he had posted (using offline token).
Ps:
I do not want this:
var wallPost = {
message : " My message",
};
FB.api('/USER_ID/feed', 'post', wallPost , function(response) {
if (!response || response.error) {
console.log("facebook error: " + response.error);
}
});
I need the post is in "FB.api ('/ME/feed', 'post', wallPost, function (response) {"
But this "ME" is not the logged user, but the user owns of the offline token.

You cannot do that with the Javascript API because the FB.api call will only use the access token for the currently logged in user. You will need to build a call directly to HTTP post the message to the https://graph.facebook.com/me/feed?access_token={the offline access token you have}

SOLUTION:
Just insert the acess_token in JSON parameter.
var wallPost = {
message : " My message",
access_token : "ACCESS_TOKEN_OFF_LINE_OF_THE_USER"
};
FB.api('/me/feed', 'post', wallPost , function(response) {
if (!response || response.error) {
console.log("facebook error: " + response.error);
}
});

Related

Connecting Facebook page and Facebook application

Goal : Connecting an application with existing Facebook page.
Why ? I want to allow user to use their page as bot. Facebook app is a bot.
Reason : User wants a bot for Facebook page but does not allow admin permissions.
What I've tried :
Get all users pages :
if ( typeof (response.authResponse) !== 'undefined')
{
token = response.authResponse.accessToken;
$.ajax({
url: "api/FB/GetCode?token=" + token,
}).done(function (data) {
var mySelect = $('.dropdown');
mySelect.empty();
$.each(data.accounts.data, function (val, text) {
mySelect.append(
$('<option></option>').val(text.access_token).html(text.name)
);
});
mySelect.show();
$('.connectWithBot').show();
});
} else {
//do the login logic
}
Then when user has chosen page :
FB.api(
'pageId/subscribed_apps?access_token=' +
$('.dropdown').find(":selected").val(),
'post',
function (response) {
console.log(response);
if (response && !response.error) {
console.log(response);
}
});
So when one page instance is connected with one application, this not gonna work anymore. Its okey that way.
Is it possible to get this work ? Or maybe you guys have a better idea ?

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) {

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

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'
});
}

Post to User Wall using offline_access in facebook Javascript Sdk

My problem is that i want to post to user wall using the offline_access.
I donot know how to do that using the facebook javascript sdk
with this method FB.api('/me/feed')
Please also give me an example how to integrate the facebook connect with asp
If the user has already authenticated and has given publish_stream or offline_access permissions, you can just call this method to publish to their feed:
var body = 'Reading Connect JS documentation';
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});

Is an onject id returned when publishing via Facebook GraphAPI?

I am planning an app that will post to a users FB wall. When posting via the GraphAPI is an object id returned for the new post? We want to use the post id later to retrieve data about the post.
If you look at FB.ui() example for stream.publish, post_id is returned with the response.
Looking at this example from their FB.api docs, it certainly seems possible.
var body = 'Reading Connect JS documentation';
FB.api('/me/feed', 'post', { body: body }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response);
}
});