我使用下面的代码将文本框内容发布到我的 facebook 墙上,效果很好。
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);
}
}
然后我创建了 facebook 页面并尝试在上面发布。为此,我也启用了管理页面权限,但我无法获取页面访问令牌。我如何能够通过 C# 代码动态获取 facebook 页面访问令牌以在其上发布。