restFB - can't post to page - only to my wall - facebook

I created a Facebook app that I will use to programatically post information to Facebook. I've got it working so that I can post to my wall, but not the page I'd like it to go to (for which I am 1 of 2 administrators).
this posts to my page just fine:
FacebookClient facebookClient = new DefaultFacebookClient("<ACCESS_TOKEN>");
FacebookType publishMessageResponse = facebookClient.publish("<MY_FB_NAME>/feed", FacebookType.class, Parameter.with("message", "Testing..."));
but if I try to post the page, I get an error:
com.restfb.exception.FacebookOAuthException: Received Facebook error response of type OAuthException: (#200) The user hasn't authorized the application to perform this action
The code is the same, except I replace my name with the page's ID:
FacebookClient facebookClient = new DefaultFacebookClient("<ACCESS_TOKEN>");
FacebookType publishMessageResponse = facebookClient.publish("<THE_PAGE_ID>/feed", FacebookType.class, Parameter.with("message", "Testing..."));
The app is listed as one of the apps for the page.
Thanks for any help with this,
Frank

Are you sure you have the correct (publish_stream) Permission?
You'll need that to post as the user to places other than their own profile.

Related

Facebook Graph API post message with link to page's wall

My problem is: When I post to page's wall some message with link it shows as Posted By Others, without link it shows normally in page timeline (Im group's admin ).
The same code posts to my timeline just fine:
I use AS3 library.
My permissions:
"publish_stream", "user_photos","publish_actions","manage_pages"
my post code:
var params:Object = new Object();
params.message = messageTextInput.text;
params.description = "description";
params.caption = "caption";
params.name = "name";
params.link = "http://www.ya.ru";
params.picture = "http://image.bayimg.com/cajchaado.jpg";
FacebookDesktop.api(page.id+"/feed", onCallApi, params, "POST"); //use POST to send data (as per Facebook documentation)
Facebook documentation says I can post either link or message, but it works just fine, except of showing in "Recent posts by others" ( please see attached screenshot ).
To post on a fanpage on behalf of itself (not the user), you have to use the page access token.
What happening is- when you make the call, the sdk uses the default token (user token), so the post is published on behalf of the user which is displayed in the "Recent Post by Others" section in the page.
Since you have requested for manage_pages already in your code, you can simply obtain the page access token with this call- /{page-id}?fields=access_token. Use this token with your current call just by adding the parameter access_token-
....
params.picture = "http://image.bayimg.com/cajchaado.jpg";
params.access_token = "{page-access-token}";
....

restfb api not support when user logout from facebook & access key generate every time

I am using RESTFb api to post a message on facebook wall
my code is:
val facebookClient: FacebookClient = new DefaultFacebookClient("access_key")
def publishMessage(msg:Mesage): String = {
val publishMessageResponse: FacebookType = facebookClient.publish("me/feed", classOf[FacebookType],
Parameter.`with`("message", msg))
publishMessageResponse.getId()
}
But this code is working only when I am login in my facebook account.If I am not login it give me the error of "user session logout". and it told me to generate the access token every time.
Thats because you are trying to post to your own Wall.. thats why, OAuth needs to validate you are logged otherwise it wont post anything... if you where posting to a PAGE... well that's diferent you could use APP and SECRET ID's to generate AccessTokens on your website.

Post on Facebook page wall or timeline

As FaceBook launched a new concept of pages, I created a page, but I am not able to find any C# SDK for posting on that page's timeline from code.
First you need C# SDK
you can download from here
http://csharpsdk.org/
may be you need manage_page permission to get a page access token
you can get a page access token using this Graph Request http://developers.facebook.com/tools/explorer/?method=GET&path=me%2Faccounts
after getting page access token you can post a on page wall using this code
var fb = new Facebook.FacebookClient(PageAccessToken);
var postArgs = new Dictionary<string, string>();
postArgs["link"] = "http://www.foo.com";
postArgs["name"] = "Click Here To View";
postArgs["message"] = Message;
fb.Post("[pageid]/feed/", postArgs);

Trying to post directly to an application's wall

I'm trying to post directly to an application's wall without linking it to my account. I keep getting a "(OAuthException) (#200) The user has not granted the application the permission to automatically publish feed stories". This is from a winform application.
var oAuthClient = new FacebookOAuthClient();
oAuthClient.AppId = "APP_ID";
oAuthClient.AppSecret = "APP_SECRET";
dynamic token = oAuthClient.GetApplicationAccessToken();
var appToken = token.access_token;
FacebookClient fbClient = new FacebookClient(appToken.ToString());
var args = new Dictionary<string, object>();
args["message"] = "Testing 123456789 from C#";
fbClient.Post("/APP_ID/feed", args);
Citing from facebook docs for stream.publish:
Posting to Your Application's Profile Page
In order to use stream.publish to post on the Wall of your application profile page (your application's About Page), all the following conditions must be true:
The posting user needs to grant the application the publish_stream extended permission.
The posting user must like the application's profile page.
A developer of the application must edit the application profile page's Wall Settings (Edit Application > Edit) and verify under Posting Ability that Fans can write or post content on the wall is checked.
From this it is obvious you cannot post to application wall with application token, only with token of user that likes the app.

facebook graph api how to post page wall

i little speak english
i want create feed (post, note, link) to page wall ANY TIME (like offline_access) with new graph api
What should I do for it , what permissions should
thank you in advance.
create facebook app
take appid
copy this link to browser
https://www.facebook.com/dialog/oauth?client_id=appid&redirect_uri=canvasurl&scope=manage_pages&response_type=token
provide appid and the url u given in canvas url(eg:http://localhost/web)
redirected url u can see access token.take that access token value.
Facebook_Graph_Toolkit.GraphApi.Api x = new Facebook_Graph_Toolkit.GraphApi.Api(accesstoken);
string id = x.PostFeedToTarget("pageid", "hi test");