Automatically publish posts to a site on a Facebook page

I have a website, and when a new message is created on my website, I want to publish it also on the Facebook page of the website (as the administrator of the Facebook page, and not for the user posting it on the website). Of course, I'm the administrator of the Facebook page. How can I do that?

The content I'm trying to publish is an image and a short description.

+4
source share
1 answer

You can use the Facebook Graph API and the Facebook SDK for .NET for your purposes.

If you want to do this with C# code, not java-script , you will have something like the code below:

WITH#

 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 } } 

See Post to feed for more details.

I hope this helps you solve your problem.

+1
source

All Articles