Facebook C# SDK how to post on wall
We used Facebook C# SDK for one of our clients to post messages on Facebook wall.
The API is easy to use and understand, and in this article we are going to describe all steps to post on Facebook wall using Facebook API.
Facebook provides Graph API for all features, including posting on the wall. The name of the method is “feed”:
https://graph.facebook.com/[ID_OF_WALL_PAGE]/feed
You have to send HTTP post message to the url above with the post object. The post object has the following properties:
- picture
- link
- message
- name
- caption
- description
- category
and it looks like this in browser
Posting on Facebook wall with C# Facebook SDK
dynamic messagePost = new ExpandoObject();
messagePost.picture = "http://yaplex.com/uploads/yaplex-logo-with-text-small.png";
messagePost.link = "http://yaplex.com/";
messagePost.name = "[name] Facebook name...";
// "{*actor*} " + "posted news..."; //<---{*actor*} is the user (i.e.: Alex)
messagePost.caption = " Facebook caption";
messagePost.description =
"[description] Facebook description...";
messagePost.message = "[message] Facebook message...";
string acccessToken =
"xxxx5120330xxxx|4xxxxx0c0f95bd3f62dxxxxx.1-10000xx4x73xxxx|2xx5xxx0566xxxx|z2xxxx37dxxxxsdDS23s_Sah34a";
FacebookClient appp = new FacebookClient(acccessToken);
try
{
var postId = appp.Post("24351740xxxxxx" + "/feed", messagePost);
}
catch (FacebookOAuthException ex)
{
//handle oauth exception
}
catch (FacebookApiException ex)
{
//handle facebook exception
}
The code is pretty easy, and the most important thing you need is Facebook Access Token.
Once you have access token, you create facebook wall message and submit it to facebook graph API url with HTTP POST request.
