且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Facebook上的粉丝页面上使用C#facebook sdk在codeplex上发布图像

更新时间:2022-10-31 13:26:38

你可以使用{id} / feed



如果你想在墙上发布图像/视频。尝试从nuget下载样品。

  Install-Package Facebook.Sample 
pre>

以下是使用图形API进行操作。

  public static string UploadPictureToWall(string id,string accessToken,string filePath)
{
var mediaObject = new FacebookMediaObject
{
FileName = System.IO.Path.GetFileName(filePath)
ContentType =image / jpeg
};

mediaObject.SetValue(System.IO.File.ReadAllBytes(filePath));

try
{
var fb = new FacebookClient(accessToken);

var result =(IDictionary< string,object>)fb.Post(id +/ photos,new Dictionary< string,object>
{
{source ,mediaObject},
{message,photo}
});

var postId =(string)result [id];

Console.WriteLine(Post Id:{0},postId);

//注意:这个json结果不是Facebook返回的原始json字符串。
Console.WriteLine(Json:{0},result.ToString());

return postId;
}
catch(FacebookApiException ex)
{
//注意:确保处理此异常。
throw;
}
}


Currently I'm working on my HTML 5 ASP.Net Application, Which has requirement of Graffiti Wall, When user draw something on my Wall(means on my HTML 5 Canvas element), and Press Share Button on my Page, at that time the whole picture should need to be post on one of the Facebook Page.

Now my question is that is this thing possible using C# facebook sdk by codeplex ? if its possible, than how to post image on facebook fan page using this SDK?? Where can I get the good resource the implement this kind of functionality or similar code.

I've check the all examples given by them, there is no any example which post on the facebook fan page.

Or even other library that can implement this kind of functionality.

I've check this library, and see that it has FacebookClient,ExpandoObject, FacebookMediaObject kind of classes, but how to and where to use this classes,where are the description and sample code.

Thanks, Jigar Shah

you can post to others wall using "{id}/feed"

if you want to post image/video on wall. Try downloading the samples from nuget.

Install-Package Facebook.Sample

Here is how to do using the graph api.

    public static string UploadPictureToWall(string id, string accessToken, string filePath)
    {
        var mediaObject = new FacebookMediaObject
                              {
                                  FileName = System.IO.Path.GetFileName(filePath),
                                  ContentType = "image/jpeg"
                              };

        mediaObject.SetValue(System.IO.File.ReadAllBytes(filePath));

        try
        {
            var fb = new FacebookClient(accessToken);

            var result = (IDictionary<string, object>)fb.Post(id + "/photos", new Dictionary<string, object>
                                   {
                                       { "source", mediaObject },
                                       { "message","photo" }
                                   });

            var postId = (string)result["id"];

            Console.WriteLine("Post Id: {0}", postId);

            // Note: This json result is not the orginal json string as returned by Facebook.
            Console.WriteLine("Json: {0}", result.ToString());

            return postId;
        }
        catch (FacebookApiException ex)
        {
            // Note: make sure to handle this exception.
            throw;
        }
    }