使用 C# 发布到 facebook 粉丝页面墙上的最简单方法

Simplest way to post to a facebook fan page#39;s wall with C#!(使用 C# 发布到 facebook 粉丝页面墙上的最简单方法!)

本文介绍了使用 C# 发布到 facebook 粉丝页面墙上的最简单方法!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的公司设置了一个粉丝页面.

I have a fan page setup for my company.

我想从我的 C# 桌面应用程序自动将定期更新发布到该页面的墙上.

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

  • 哪个 Facebook C# 库最简单?

  • Which Facebook C# library is the simplest?

如何轻松获取此页面的访问令牌?

How can I easily acquire the access token for this page?

什么是最简洁的代码片段,可以让我发布到墙上?

What is the most concise code snippet that will simply allow me to then post to the wall?

我已经阅读了所有文档以及数百万的 stackoverflow 和博客文章,这一切似乎都非常令人费解.当然不会那么难..

I have read through all the docs and millions of stackoverflow and blog posts and it all seems very convoluted. Surely it can't be that hard..

我在 facebook 中设置了一个应用程序",它有自己的 App ID、API Key 和 App Secret 等.

I have setup an "application" within facebook that has its own App ID, API Key and App Secret etc.

推荐答案

@Aaron - 最好的库是 facebook c# sdk.我每天都在使用它……当然,正如我的公司所写的那样,我有偏见 - 但它是一个动态库,而且 Facebook 的更新速度(每周二)非常适合可扩展的开发.

@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/

我不会使用它进行身份验证 - 因为在 codeplex 上有很多示例:http://facebooksdk.codeplex.com/wikipage?title=Code%20Examples&referringTitle=Documentation但是要在页面上发布帖子,在您通过身份验证并获得访问令牌后,代码将是这样的:

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
}

希望这会有所帮助.

这篇关于使用 C# 发布到 facebook 粉丝页面墙上的最简单方法!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:使用 C# 发布到 facebook 粉丝页面墙上的最简单方法

基础教程推荐