facebook c# sdk getting started

情到浓时终转凉″ 提交于 2019-11-28 18:59:17

Here is what I found.

Download the facebook C# sdk source code and samples from http://facebooksdk.codeplex.com/

Unzip the code and load into Visual Studio the Facebook C# SDK sample called CS-WinForms.

At the top of Form1.cs - enter your application ID

Run the application.

Form1.cs pops up with a button "Login to Facebook". Click the button.

FacebookLoginDialog.cs pops up with a browser window in it displaying facebook asking for permissions.

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 means the AccessToken you get - never expires

Click "OK" in Facebook to allow the application to access your facebook data.

FacebookLoginDialog.cs should find that you logged in and get the access token that never expires.

The access token is a string.

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

to post message to Facebook!

You should request offline_access in addition to publish_stream. Once you have the never-expiring token, store that in your app.

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