Post to wall fail when a picture is added

久未见 提交于 2019-12-08 06:05:40

问题


I've managed to post to a user wall, but when i try to add a picture to the parameters of the post, the post fails and the Result is null. I think that i´m doing everything alright, but i could use some help. Thanks in advance!

 IDictionary<string, object> parameters = new Dictionary<string, object>();
                    parameters["access_token"] = fbAccessToken;
                    parameters["name"] = "my picture";
                    parameters["message"] = "this is a picture uploaded from my the facebook sdk";                        

                   parameters.Add("picture", "http://t2.gstatic.com/images?q=tbn:Bebedm7ldqvC3M:http://www.configmac.com/images/logiciel/image.jpg");

                    fbApp.PostAsync("me/feed", parameters, (val) =>
                    {
                        if (val.Error == null)
                        {
                            // Asyncronous call, only executed after obtaining Facebook response
                            var result = (IDictionary<string, object>)val.Result;
                        }
                        else
                        {
                        }
                    });

回答1:


var picture = File.ReadAllBytes("a.jpg");
var fb = new FacebookClient(_accessToken);

fb.PostCompleted +=
    (o, args) =>
    {
        if (args.Error == null)
        {
            MessageBox.Show("Picture posted to wall successfully.");
        }
        else
        {
            MessageBox.Show(args.Error.Message);
        }
    };

dynamic parameters = new ExpandoObject();
parameters.caption = txtMessage.Text;
parameters.method = "facebook.photos.upload";

var mediaObject = new FacebookMediaObject
                      {
                          FileName = Path.GetFileName(ofd.FileName),
                          ContentType = "image/jpeg"
                      };
mediaObject.SetValue(picture);
parameters.source = mediaObject;

fb.PostAsync(parameters);


来源:https://stackoverflow.com/questions/5260273/post-to-wall-fail-when-a-picture-is-added

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!