I used the below code to post the text box content into my facebook wall and it's works fine.
private void btn_Post_Click(object sender, EventArgs e)
{
string appID, appSecret, userId;
appID = ConfigurationManager.AppSettings["AppID"].ToString();
appSecret=ConfigurationManager.AppSettings["AppSecret"].ToString();
userId = ConfigurationManager.AppSettings["UserID"].ToString();
var fb = new FacebookClient();
dynamic result = fb.Get("oauth/access_token", new
{
client_id = appID,
client_secret = appSecret,
grant_type = "client_credentials"
});
fb.AccessToken = result.access_token;
PostToWall(txt_status.Text, userId, fb.AccessToken);
}
private static void PostToWall(string message, string userId, string wallAccessToken)
{
try
{
var fb = new FacebookClient(wallAccessToken);
string url = string.Format("{0}/{1}", userId, "feed");
var argList = new Dictionary<string, object>();
argList["message"] = message;
fb.Post(url, argList);
MessageBox.Show("Posted");
}
catch (Exception ex)
{
MessageBox.Show("Error:" + ex.Message);
}
}
Then i have created the facebook page and trying to post on it. For that i enabled the manage page permission too but i could not able to get the page access token. How can i able to get the facebook page access token dynamically through the C# code to post on it.