How to post on facebook wall

Posting/adding data into facebook
Facebook is the most widely used Social Networking site. Thus it will be greatly beneficial for facebook users if they can directly access data outside facebook in their own web sites. This data includes a user’s friend list, live feeds, wall posts and many more.

Here I have explained how to post to one’s facebook wall using C#:-

User needs to obtain an access token from facebook developers’ site by creating a new app there. For more information on obtaining an access token refer the tip below:-

“http://www.ourgoalplan.com/KLMS/TipView.aspx?id=2501”

facebook provides a service called Graph API that allows an user to easily access all public information about an object. All responses returned by this Api are JSON objects. Wall Posts can be made to one’s facebook wall via a connection in Graph API viz.

“https://graph.facebook.com/me/feed?access_token=…&message=…”

A server-side validation of facebook certificate is done.

ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(ValidateFacebookCertificate);

private static bool ValidateFacebookCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors policyErrors)

{

return true;

}

The JSON object returned is then parsed. Parsing is done to recognize only JSON text filtering out all malicious JSON scripts. JSON parsers are much faster.

Jobject mypostStatus =JObject.Parse(“https://graph.facebook.com/me/feed?access_token=…&message=…”);
NOTE:-The message here can pe posted from a be. E.g:-message=txtPostWall.Text

A Web Request is created for the URI. To access the HTTP-Specific properties, the WebRequest is cast to HTTPWebRequest .

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(“https://graph.facebook.com/me/feed?access_token=…&message=…”);

The method of the Request is defined as either POST or GET. Since here we need to post/add data into facebook the method here is POST.

request.Method = “POST”;

The request is then sent to the server by using GetResponse( ) method.

HttpWebResponse response = (HttpWebResponse)request.GetResponse( );

Then the stream containing the response data is sent by the sever by using the GetResponseStream( ) method. A StreamReader is used to open the stream for easy access.

StreamReader reader = new StreamReader (response.GetResponseStream( ));

The entire content is then read by calling the ReadToEnd( ) method.

string retrnVal = reader.ReadToEnd();

150 150 Burnignorance | Where Minds Meet And Sparks Fly!