无法更新Facebook页面应用custom_image

时间:2013-10-10 20:00:02

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

我正在尝试使用图形api更新我的页面应用图片,但没有任何反应。我有正确的访问令牌,我可以更改custom_name但不能更改custom_image。

                    var fbdc = new Dictionary<string, object>();
                    fbdc.Add("access_token", AccessToken);
                    fbdc.Add("custom_name", Name);
                    fbdc.Add("custom_image",Image);
                    result = fb.Post(tab.id, fbdc);

我从图形api得到的结果是真的,但图像仍然没有变化。我的图像是111 * 74.jpg。我能够手动上传相同的图像,但不能通过图形API。 我做错了吗?

1 个答案:

答案 0 :(得分:0)

var fbparams = new Dictionary<string, object>();
          string path = @"c:\test.jpg";
          FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
      var picture = new FacebookMediaObject
                {
                        //Tell facebook that we are sending image
                    ContentType = "image/jpeg",
                    //Give name to the image
                    FileName = "test"
                };
                //Create a new byteArray with right length
                var img = tabImageInfo.Media;
                //Convert the image content into bytearray
               fs.Read(img, 0, img.Length);
                 //Close the stream
               fs.Close();
                //Put the bytearray into Picture
                picture.SetValue(img);
                //Add the image into parameters
                fbparams.Add("custom_image", picture);
        fb.Post(tab.id, fbparams);