facebook c# sdk getting started

后端 未结 2 1041
自闭症患者
自闭症患者 2020-12-13 23:28

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

I have signed up for facebook developer and have a

相关标签:
2条回答
  • 2020-12-13 23:34

    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!

    0 讨论(0)
  • 2020-12-13 23:35

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

    0 讨论(0)
提交回复
热议问题