Facebook的C#SDK入门 [英] facebook c# sdk getting started

查看:240
本文介绍了Facebook的C#SDK入门的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个控制台应用程序,每天早上一次自动职位信息到我的墙上。

I would like to write a console application that automatically posts information to my wall once every morning.

我已经注册了Facebook的开发者和拥有的AppID和App揭秘

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 ???

什么是前进的正确方法?

What is the proper way to proceed?

似乎所有我需要的是:
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使用folling网址:

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&安培;范围= user_about_me,publish_stream,offline_access

它返回一个WebBrowser.DocumentText ACCESSKEY

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



我得到异常:

I get the exception:

( 。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);



然后,我得到异常:

Then I get the exception:

(OAuthException)有效的访问令牌,必须使用查询有关当前用户的信息。

(OAuthException) An active access token must be used to query information about the current user.

我猜是相同的异常

推荐答案

下面是我发现的。

下载从的 http://facebooksdk.codeplex.com/

解压缩码,并加载到Visual Studio称为CS-的WinForms Facebook的C#SDK示例

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的OK,以允许应用程序访问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/tool​​s/debug/access_token
。您可以输入您的访问令牌,然后单击调试,它应该列出你的applicationID,用户名,并为过期,应该说从来没有。

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入门的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆