简体   繁体   中英

Image not uploaded after publishing using facebook c# SDK

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 .

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");
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM