I have written below function to post single Photo to FB page. But getting error saying "(OAuthException - #200) (#200) Unpublished posts must be posted to a page as the page itself."
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
}
}
Please help me on this.
--
Regards
Deepak Rai
I got it myself. There are multiple types of tokens. In my above code I was passing "user access token" Instead I had to pass "page access token". To generate "page access token" use get method for using below URL:
string url = string.Format(
"https://graph.facebook.com/{0}?fields=access_token&access_token={1}",
pageID, user_access_token);
Hope this will help :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With