-1

我在将照片发布到 facebook 时遇到问题。任何人都知道怎么做。请帮忙。谢谢。

  FacebookClient fb = new FacebookClient(App.AccessToken);

                fb.PostCompleted += (o, e) =>
                {
                    if (e.Error != null)
                    {
                        Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message));
                        return;
                    }

                    var result = (IDictionary<string, object>)e.GetResultData();

                    Dispatcher.BeginInvoke(() =>
                    {
                        MessageBox.Show("Success post message to the wall.");
                        // reset the selections after the post action has successfully concluded
                        tbmessage.Text = "";
                    });
                };

                var parameters = new Dictionary<string, object>();
                parameters["name"] = tbmessage.Text;

                dynamic res = fb.PostTaskAsync("me/photos", parameters);
4

1 回答 1

0

在参数列表中,您必须通过以下任一方式提供图像源:

  • url: 图片的有效 url

  • source: 图像数据

[代码]

[HttpPost]
    public ActionResult PostPhotoOnWall(HttpPostedFileBase file)
    {
        var filename = Path.GetFileName(file.FileName);
        StreamResourceInfo sri = null;
        Uri jpegUri = new Uri(filename, UriKind.Relative);
        sri = Application.GetResourceStream(jpegUri);
        byte[] imageData = new byte[sri.Stream.Length];
        sri.Stream.Read(imageData, 0, System.Convert.ToInt32(sri.Stream.Length));

        var client = new FacebookClient();

        // Post to user's wall
        var postparameters = new Dictionary<string, object>();
        var media = new FacebookMediaObject
        {
            FileName = filename,
            ContentType = "image/jpeg"
        };
        media.SetValue(imageData);

        postparameters["source"] = media;
        postparameters["access_token"] = Session["access_token"].ToString();

        var result = client.Post("/me/photos", postparameters);

        return View("PostPhoto");
    }
于 2013-08-16T08:16:08.097 回答