我已经写下了将单张照片发布到FB页面的功能。但是收到错误说“(OAuthException - #200)(#200)未发布的帖子必须作为页面本身发布到页面。”
private void postToFBPage()
{
string app_id = ConfigurationManager.AppSettings["FBAppKey"];
string app_secret = ConfigurationManager.AppSettings["FBSecretKey"];
string scope = ConfigurationManager.AppSettings["FBPermission"];
string access_token;
if (Session["access_token"] == null)
access_token = getAccessToken();
else
access_token = Session["access_token"].ToString();
var client = new FacebookClient(access_token);
List<string> imgs = (List<string>)Session["local_processedImgs"];
DateTime dt=new DateTime(Convert.ToInt32(ddlYear.SelectedValue)
,Convert.ToInt32(ddlMonth.SelectedValue)
,Convert.ToInt32(ddlDate.SelectedValue)
,Convert.ToInt32(ddlHour.SelectedValue)
,Convert.ToInt32(ddlMin.SelectedValue)
,0);
double UTC = Facebook.DateTimeConvertor.ToUnixTime(dt);
dynamic post = null;
dynamic parameters = new ExpandoObject();
parameters.source = new FacebookMediaObject
{
ContentType = "image/" + Path.GetExtension(imgs[0]),
FileName = imgs[0]
}.SetValue(File.ReadAllBytes(imgs[0]));
parameters.message = CKEditor1.Text;
parameters.scheduled_publish_time = UTC;
parameters.published = false;
parameters.scope = scope;
try
{
post = client.Post("/" + ddlFBPage.SelectedValue + "/photos" , parameters);
}
catch (Exception ex)
{
//error
}
}
请帮我解决这个问题。
-
此致
Deepak Rai
答案 0 :(得分:5)
我自己得到了它。有多种类型的令牌。在上面的代码中,我传递了“用户访问令牌”而不是我必须传递“页面访问令牌”。要生成“页面访问令牌”,请使用get方法使用以下URL:
string url = string.Format(
"https://graph.facebook.com/{0}?fields=access_token&access_token={1}",
pageID, user_access_token);
希望这会有所帮助:)