How to post image on facebook fan page using C# facebook sdk on codeplex

守給你的承諾、 提交于 2019-12-11 02:27:10

问题


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


回答1:


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;
        }
    }


来源:https://stackoverflow.com/questions/5335290/how-to-post-image-on-facebook-fan-page-using-c-sharp-facebook-sdk-on-codeplex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!