使用facebook c#SDK发布后图片未上传

时间:2012-10-31 14:15:15

标签: c# facebook facebook-graph-api facebook-c#-sdk

我使用Facebook c#SDK发布状态&用户墙上的图像。

我可以发布状态,但图片未发布

这是我的代码:

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

发布用户墙状态时没有图像。

任何人都可以帮助我。

1 个答案:

答案 0 :(得分:1)

我解决了它,贝娄是代码

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