Hallo我正在开发一个C#控制台应用程序,它必须将消息和图像发布到Facebook。我已经有了第一部分工作,现在认证令牌不是问题。但是我的程序上传任何类型的媒体都遇到了很多麻烦。
如果有人能帮助我,我将非常感激,我在实习的最后几天一直在了解Facebook Api和Sdk,但我并没有真正取得进展。
这是我到目前为止的代码:
using Facebook;
using System;
using System.Dynamic;
namespace ApiHandlerFacebook
{
class Program
{
static void Main(string[] args)
{
PostMessage();
Console.WriteLine("\nPress the Enter key to exit the application...\n");
Console.ReadLine();
Console.WriteLine("Terminating the application...");
}
private static void PostMessage()
{
//Fill the brackets with a access token to test the application
//You can easily get a temporary token using the Graph Api Explorer from Facebook: https://developers.facebook.com/tools/explorer/
//But do make sure you have the "publish_actions" permission otherwise it wont work.
string access_token = "ACCESS_TOKEN_HERE";
dynamic parameters = new ExpandoObject();
parameters.message = "Test Message";
parameters.subject = "test 123";
parameters.link = "https://youtu.be/dQw4w9WgXcQ";
parameters.picture = "http://b.vimeocdn.com/ps/588/58832_300.jpg";
parameters.name = "Article Title";
parameters.caption = "Caption for the link";
parameters.description = "Longer description of the link";
parameters.privacy = new
{
value = "SELF"
};
var client = new FacebookClient(access_token);
client.Post("/me/feed", parameters);
Console.WriteLine("Posted");
}
}
}
编辑1: 为了使它更清楚:
编辑2: 我仍然有一些代码,我正在尝试发布不起作用的图像,但也许你们中的一个知道如何让它工作:
FacebookMediaObject media = new FacebookMediaObject
{
FileName = "TestImage.jpg",
ContentType = "image/jpeg"
};
byte[] img = File.ReadAllBytes("http://static.mnium.org/images/contenu/actus/Overwatch/Ocarine/D.va/d_va__by_guweiz.jpg");
media.SetValue(img);
parameters.source = media;