Post image on facebook wall using c#

Hi,

Are you looking for image posting on your Facebook wall using c#?.

Please follow the steps as follows :

[Ignore this step if you have created application in Facebook and done with login  functionality]
Step 1: Create application into Facebook, Login using javascript and get the access token :
http://narendrajarad.blogspot.in/2014/07/facebook-login-using-javascript.html

[Ignore this step if you have already added reference of Facebook from NuGet packages to your project]
Step 2: Add a reference to Facebook to your project :
http://narendrajarad.blogspot.in/2014/07/add-reference-of-facebook-from-nuget-to.html


Finally use this below code to "Post image on Facebook wall using c#":

 var imageName = Path.GetimageName("Images/1.png");
 var client = new FacebookClient(hdfAccessToken.Value);
var postparameters = new Dictionary<string, object>();
var media = new FacebookMediaObject
{
FileName= imageName,
ContentType = "image/jpeg"
};
var path = Path.Combine(Server.MapPath("~/Images/"), imageName);
byte[] img = System.IO.File.ReadAllBytes(path);
media.SetValue(img);
postparameters["source"] = media;
postparameters["access_token"] = hdfAccessToken.Value;
var result = client.Post("/me/photos", postparameters);

Comments