我想使用Facebook图形api将状态更新发布到我的提要,并在磁盘上添加一张照片. 这是否可能,或者我必须提供图像的超链接地址吗? 我知道可以使用 Post 对象的source参数,但我正在寻找一种方法来附加图像文件进行状态更新.
I want to post a status update to my feed and add a photo residing on disk, using the facebook graph api. Is this possible or must I provide be a hyperlink address to the image? I know it's possible to add a photo to an album using the Post object's source parameter but I'm looking for a way to do a status update with a image file attached.
推荐答案由于我们已经使用发布到图形API的Facebook C#API将图像直接发布到相册和墙壁上,因此绝对有可能
It is definitely possible as we have published images directly to Albums and Walls using the Facebook C# API which posts to the graph API
我们使用FacebookMediaObject来实现此目的,但我相信这只是创建所需的邮政表格数据.这里是代码,因此您可以看一下是否有帮助:
We use the FacebookMediaObject to achieve this but I believe this simply creates the post form data required. Here is out code so you can take a look if it helps:
var facebookClient = new FacebookClient(entry.AccessToken); var mediaObject = new FacebookMediaObject { FileName = filename, ContentType = "image/jpeg" }; var fileBytes = System.IO.File.ReadAllBytes(filename); mediaObject.SetValue(fileBytes); IDictionary<string, object> upload = new Dictionary<string, object>(); upload.Add("name", imagename); upload.Add("message", message); upload.Add("@file.jpg", mediaObject); var result = facebookClient.Post("/" + albumId + "/photos", upload) as JsonObject;请注意字段名称"@ file.jpg";分配了mediaObject的对象.
Note the field name of "@file.jpg" which the mediaObject is assigned.
希望这会有所帮助.
您可能必须先将图像发布到用户墙上,并获得一个对象ID,然后可以在对象中使用object_id字段引用该ID.
You may have to post the image to the users wall first and recieve an object ID which you can then reference in the post with the object_id field.
更多推荐
是否可以发布状态更新并使用facebook graph API添加图像文件?
发布评论