Reputation: 5069
I am using Facebook c# SDK to post status & images on users wall.
I am able to post status but image is not getting posted
Here is my code:
[HttpPost]
public ActionResult PostPhotoOnWall(HttpPostedFileBase file)
{
var client = new FacebookClient();
// Post to user's wall
var postparameters = new Dictionary<string, object>();
postparameters["access_token"] = Session["access_token"].ToString();
postparameters["picture"] = "http://localhost:8691/Content/themes/base/images/12WIPJ50240-2V91.jpg";
var result = client.Post("/me/feed", postparameters);
return View("PostPhoto");
}
On user wall status is posted without image.
Can any one help me .
Upvotes: 1
Views: 788
Reputation: 5069
I Solved It, Bellow is the code
[HttpPost]
public ActionResult PostPhotoOnWall(HttpPostedFileBase file)
{
var filename = Path.GetFileName(file.FileName);
var client = new FacebookClient();
// Post to user's wall
var postparameters = new Dictionary<string, object>();
var media = new FacebookMediaObject
{
FileName = filename,
ContentType = "image/jpeg"
};
var path = Path.Combine(Server.MapPath("~/Content/themes/base/images"),filename);
file.SaveAs(path);
byte[] img = System.IO.File.ReadAllBytes(path);
media.SetValue(img);
postparameters["source"] = media;
postparameters["access_token"] = Session["access_token"].ToString();
// postparameters["picture"] = "http://localhost:8691/Content/themes/base/images/12WIPJ50240-2V91.jpg";
var result = client.Post("/me/photos", postparameters);
return View("PostPhoto");
}
Upvotes: 1