Simplest way to post to a facebook fan page's wall with C#!

后端 未结 3 1806
轮回少年
轮回少年 2020-12-30 10:09

I have a fan page setup for my company.

I want to automate the posting of regular updates to that page\'s wall from my C# desktop application.

  • Which

3条回答
  •  不知归路
    2020-12-30 10:33

    @Aaron - the best library is the facebook c# sdk. I use it every day... granted I am biased as my company writes it - but it's a dynamic library and with the rate of updates from Facebook (every Tuesday) it is well suited for scalable development.

    http://facebooksdk.codeplex.com/

    I won't get into authentication with it - as on codeplex there are many examples: http://facebooksdk.codeplex.com/wikipage?title=Code%20Examples&referringTitle=Documentation But to do a post to a page, after you have authenticated and have an access token, the code would be something like this:

    dynamic messagePost = new ExpandoObject();
    messagePost.access_token = "[YOUR_ACCESS_TOKEN]";
    messagePost.picture = "[A_PICTURE]";
    messagePost.link = "[SOME_LINK]";
    messagePost.name = "[SOME_NAME]";
    messagePost.caption = "{*actor*} " + "[YOUR_MESSAGE]"; //<---{*actor*} is the user (i.e.: Aaron)
    messagePost.description = "[SOME_DESCRIPTION]";
    
    FacebookClient app = new FacebookClient("[YOUR_ACCESS_TOKEN]");
    
    try
    {
        var result = app.Post("/" + [PAGE_ID] + "/feed", messagePost);
    }
    catch (FacebookOAuthException ex)
    {
         //handle something
    }
    catch (FacebookApiException ex)
    {
         //handle something else
    }
    

    Hope this helps.

提交回复
热议问题