
我使用下面的代码将文本框内容发布到我的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页面访问令牌,以便在上面发布。
发布于 2016-07-25 20:04:20
有两个API端点可用于获取页面令牌:
获取包含页面标记的所有页面的列表
/me/accounts?fields=name,access_token获取特定页面的页面令牌:
/page-id?fields=access_token如果要使用令牌作为页面发布,请确保使用manage_pages和publish_pages进行授权。
https://stackoverflow.com/questions/38566202
复制相似问题