简体   繁体   English

使用C#SDK将媒体发布到Facebook中的用户/页面墙

[英]Post Media to User/Page Wall in Facebook with C# SDK

I'm using Facebook .Net SDK( http://facebooksdk.net/ ) in my application. 我在应用程序中使用Facebook .Net SDK( http://facebooksdk.net/ )。 I need post an image to the wall of the user or his page. 我需要将图像发布到用户或他的页面的墙上。

I have this piece of code to try do this: 我有这段代码尝试执行此操作:

var postUrl = "<fbid>/feed";
var fbParameters = new Dictionary<string,object>();
fbParameters["message"] = postRequest.FacebookPostContent;
if (postRequest.MediaData != null && postRequest.MediaData.Length > 0)
{
     var stream = new MemoryStream(postRequest.MediaData);
     if (postRequest.ContentType.Equals("image/jpeg"))
     {
       postUrl = postUrl.Replace("/feed", "/photos");
       fbParameters["picture"] = new FacebookMediaStream { ContentType = postRequest.ContentType, FileName = DateTime.UtcNow.ToString("ddmmyyyyhhmmss") + "-photo.jpeg" }.SetValue(stream);
      }
}
if (!string.IsNullOrWhiteSpace(postRequest.FacebookPageId))
{
      fbUserID = postRequest.FacebookPageId;
}
postUrl = postUrl.Replace("<fbid>", fbUserID);
var result = await facebookClient.PostTaskAsync(postUrl, fbParameters);

Look at my postUrl variable. 看一下我的postUrl变量。 I update the with the user ID in Facebook or the PageID if it is a page so the post should be properly posted in the right object. 我使用Facebook中的用户ID或PageID(如果它是页面)来更新,因此帖子应正确地发布在正确的对象中。 If there is some image to upload, so add it to the dictionary. 如果有要上传的图片,请将其添加到词典中。

So, with it in mind, I have the following questions: 因此,考虑到这一点,我有以下问题:

  1. When the fbUserID is a user ID, the post happens perfectly, with the image and description but, when the ID is a PageID, only the description text is posted and image is just ignored(the user has the manage_page permissions so I dont think it is a permission issue). 当fbUserID是用户ID时,发布会完美地进行,带有图像和描述,但是,当ID是PageID时,仅描述文本被发布,而图像则被忽略(用户具有manage_page权限,所以我认为它不是权限问题)。 What I'm doing wrong that the image is not being posted to the page's wall? 图像未发布到页面的墙上,这是我做错了吗?
  2. If I want to post a video instead of a image, what should I change in this code? 如果我要发布视频而不是图像,则该代码应更改什么?

Already saw many problems with other technologies here in SO but never a conclusive solution. 在SO中已经看到了其他技术的许多问题,但从来没有一个最终的解决方案。

Thank you very much for the help, I really appreciate. 非常感谢您的帮助,非常感谢。

Regards, Gutemberg 此致Gutemberg

Got it! 得到它了!

Facebook creates a different section inside the page called Recent Posts by Others on Test Page where people allowed to post images will be there, like an attachment icon. Facebook在页面的“ 测试页面的其他人的最新帖子 ”页面中创建了一个不同的部分,允许人们发布图像的人将在那里,如附件图标。 In order to post directly to the page's feed/wall, all I need to do is instead of use the user access_token(even if user granted manage_pages permission) just use the access_token that comes in /me/accounts object for the respective page. 为了直接发布到页面的提要/墙上,我要做的就是代替使用用户access_token(即使用户已授予manage_pages权限),也只需使用相应页面的/ me / accounts对象中附带的access_token。

About the video post, I just set the ContentType to " video/mpeg " and at server instead of set picture parameter on dictionary, I've set the video field with the video byte[]. 关于视频帖子,我只是将ContentType设置为“ video / mpeg ”,并且在服务器上而不是在字典上设置picture参数,而是将video字段设置为video byte []。

Thanks! 谢谢!

Regards, 问候,

As an alternative you could try the Share Content button shown in one of the answers here: 作为替代方案,您可以尝试在此处的答案之一中显示的“共享内容”按钮:

Upload video on Facebook using Graph REST API on Windows Phone 8.1 使用Windows Phone 8.1上的Graph REST API在Facebook上上传视频

I found that to be easier than tackling authorization and manually posting. 我发现这比处理授权和手动发布要容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM