Reputation: 34180
I have a website and when a new post is created in my website I want to publish it in the website's Facebook page too (as the Facebook page admin, not the user who is posting it on the website). Of course I'm the admin of the Facebook page. How can it be done?
The content I'm trying to publish are an image and a little description.
Upvotes: 4
Views: 378
Reputation: 2356
You can use Facebook Graph API and Facebook SDK for .NET for your purposes.
If you want to do that with C#
code, not java-script
, you'll have something like code below:
C#
private void SendToFacebook(string facebookUserScreenName, string fbAppToken, string link, string linkName, string message, string caption, string imageUrl)
{
var client = new FacebookClient(fbAppToken);
dynamic feedRez = client.Get(facebookUserScreenName);
var userId = feedRez.id;
var url = String.Format("https://graph.facebook.com/{0}/feed?access_token={1}", userId, fbAppToken);
var req = WebRequest.Create(url);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
var post = String.Format("{0}&message={1}&link={2}&name={3}&caption={4}&picture={4}",
HttpUtility.UrlEncode(fbAppToken),
HttpUtility.UrlEncode(message),
HttpUtility.UrlEncode(link),
HttpUtility.UrlEncode(linkName),
HttpUtility.UrlEncode(caption),
HttpUtility.UrlEncode(imageUrl));
var byteArray = Encoding.UTF8.GetBytes(post);
var stream = req.GetRequestStream();
stream.Write(byteArray, 0, byteArray.Length);
stream.Close();
try
{
WebResponse response = req.GetResponse();
}
catch (Exception ex)
{
//log exception
}
}
To get more details see Publish to Feed
I hope it help you to solve your problem
Upvotes: 1