从 3 天开始,我尝试了如何使用 c# 创建我的粉丝页面墙的帖子,我注意到两件事:-Facebook 提供未更新的文档,没有完整和糟糕的示例(api 经常更改)-Facebook 经常更改他的 api 和大量帖子已过时。有人可以更正我的代码或为我提供完整的好代码吗?
这是我的代码:
if (String.IsNullOrEmpty(Request.QueryString["code"]))
{
Response.Redirect("https://graph.facebook.com/oauth/authorize?client_id=157873644371673&redirect_uri=http://localhost:2551/Default.aspx&scope=publish_stream,manage_pages,offline_access&display=popup");
}
else
{
FacebookClient fb = new FacebookClient();
dynamic result1 = fb.Get("oauth/access_token", new
{
client_id = "MY_APP_ID",
client_secret = "MY_SECRET_ID",
grant_type = "client_credentials",
redirect_uri = "www.mysite.com"
});
fb.AppId = "MY_APP_ID";
fb.AppSecret = "MY_SECRET_ID";
fb.AccessToken = result1.access_token;
dynamic parameters = new ExpandoObject();
parameters.message = "Check out this funny article";
parameters.link = "http://www.example.com/article.html";
parameters.picture = "http://www.example.com/article-thumbnail.jpg";
parameters.name = "Article Title";
parameters.caption = "Caption for the link";
parameters.description = "Longer description of the link";
parameters.req_perms = "manages_pages";
parameters.scope = "manages_pages";
parameters.actions = new
{
name = "View on Zombo",
link = "www.zombo.com",
};
parameters.privacy = new
{
value = "ALL_FRIENDS",
};
try
{
var result = fb.Post("/" + "MY_FACEBOOK_FAN_PAGE_ID" + "/feed", parameters);
}
catch (FacebookOAuthException ex)
{
//handle something
Response.Write(ex.Message);
}
}