是否可以发布状态更新并使用facebook graph API添加图像文件?

编程入门 行业动态 更新时间:2024-10-06 18:26:51
本文介绍了是否可以发布状态更新并使用facebook graph API添加图像文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想使用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添加图像文件?

本文发布于:2023-10-10 18:13:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479353.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像文件   状态   graph   facebook   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!