1

我正在使用 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");
    }

用户墙上状态张贴没有图像。

谁能帮我 。

4

1 回答 1

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");
    }
于 2012-11-01T18:06:52.720 回答