我想编写一个控制台应用程序,每天早上自动将信息发布到我的墙上一次.
I would like to write a console application that automatically posts information to my wall once every morning.
我已注册 facebook developer 并拥有 AppID 和 App Secret
I have signed up for facebook developer and have a AppID and App Secret
我一直在尝试使用 C# facebook SDK 并查看了几个示例.
I have been trying to play with the C# facebook SDK and looked through several examples.
似乎示例获取了用户令牌 - 但必须使用 Windows 窗体中的浏览器.这是一个自动化过程 - 所以我不想让用户在场.
Seems like the examples get a user token - but have to use a browser that is in windows forms. This is an automated process - so I dont want to have a user present.
我还使用应用程序令牌创建了一些示例 - 但它似乎无法写入墙上.
Ive also created some examples using the application token - but it does not seem to be able to write to the wall.
我很快就写了相当于 Twitter 的东西.我一定是在这里遗漏了什么???
I wrote the Twitter equivalent very quickly. I must be missing something here ???
正确的方法是什么?
看来我只需要:FaceBookClient(appID, appSecret)然后就FaceBookClient.Put(消息)???
It seems that all I should need to is: FaceBookClient(appID, appSecret) and then just FaceBookClient.Put(message) ???
补充说明:
使用 C# facebook sdk winform 应用程序我不得不更改他们的 FacebookLoginDialog.cs 以使用以下 URL:
Playing with the C# facebook sdk winform application I had to change their FacebookLoginDialog.cs to use the folling URL:
https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=APPID&client_secret=APPSECRET&scope=user_about_me,publish_stream,offline_access
在 WebBrowser.DocumentText 中返回一个访问键
which returns an accesskey in WebBrowser.DocumentText
如果我再打电话:
var fb = new FacebookClient(_accessToken);
dynamic parameters = new ExpandoObject();
parameters.message = "Hello World!";
dynamic result = fb.Post("me/feed", parameters);
我得到了例外:
(OAuthException) 必须使用活动访问令牌来查询有关当前用户的信息.
(OAuthException) An active access token must be used to query information about the current user.
如果我将上面的代码更改为不使用该访问令牌 - 而是使用 appID 和 Appsecret:
If I change the code above to NOT use that access token - but use the appID and Appsecret:
FacebookClient myFacebookClient = new FacebookClient("APPID", "APPSECRET");
dynamic parameters = new ExpandoObject();
parameters.message = "Hello World!";
dynamic result = myFacebookClient.Post("me/feed", parameters);
然后我得到了异常:
(OAuthException) 必须使用活动访问令牌来查询有关当前用户的信息.
(OAuthException) An active access token must be used to query information about the current user.
我猜是同一个例外
这是我找到的.
从 http://facebooksdk.codeplex.com/ 下载 facebook C# sdk 源代码和示例
Download the facebook C# sdk source code and samples from http://facebooksdk.codeplex.com/
解压缩代码并将名为 CS-WinForms 的 Facebook C# SDK 示例加载到 Visual Studio 中.
Unzip the code and load into Visual Studio the Facebook C# SDK sample called CS-WinForms.
在 Form1.cs 的顶部 - 输入您的应用程序 ID
At the top of Form1.cs - enter your application ID
运行应用程序.
Form1.cs 弹出一个按钮登录到 Facebook".单击按钮.
Form1.cs pops up with a button "Login to Facebook". Click the button.
FacebookLoginDialog.cs 会弹出一个浏览器窗口,其中显示 facebook 请求权限.
FacebookLoginDialog.cs pops up with a browser window in it displaying facebook asking for permissions.
FacebookLoginDialog.cs 创建一个浏览器窗口,该窗口将转到您在 Facebook 上的用户并请求权限.默认情况下,这些权限是:user_about_me、publish_stream、offline_access.
FacebookLoginDialog.cs creates a browser window that will go to your user on facebook and request permissions. By default those permissions are: user_about_me,publish_stream,offline_access.
Offline_access 表示您获得的 AccessToken - 永不过期
Offline_access means the AccessToken you get - never expires
在 Facebook 中单击确定"以允许应用程序访问您的 Facebook 数据.
Click "OK" in Facebook to allow the application to access your facebook data.
FacebookLoginDialog.cs 应该会发现您已登录并获得永不过期的访问令牌.
FacebookLoginDialog.cs should find that you logged in and get the access token that never expires.
访问令牌是一个字符串.
The access token is a string.
插入一个断点,以便您可以复制此访问令牌.保存此访问令牌,以便以后使用它访问 Facebook.
Insert a break point so that you can copy this access token. Save this access token as you can use it from now on to access to Facebook.
Facebook 开发者网站有一些工具可以用来检查访问令牌https://developers.facebook.com/tools/debug/access_token您可以输入您的访问令牌并单击调试",它应该列出您的应用程序 ID、用户 ID,对于过期",它应该显示从不".
Facebook developers website has some tools that you can use to check the access token https://developers.facebook.com/tools/debug/access_token You can enter your access token and click "Debug" and it should list your applicationID, UserID, and for "expires" it should say "never".
一旦你有了这个访问令牌,你就可以简单地编写如下代码:
Once you have this access token - then you can simply write code like:
var fb = new FacebookClient(AccessToken);
dynamic parameters = new ExpandoObject();
parameters.message = FacebookString;
dynamic result = fb.Post("me/feed", parameters);
var id = result.id;
向 Facebook 发布消息!
to post message to Facebook!
这篇关于facebook c# sdk 入门的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!