Getting started with facebook c # sdk

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

I registered for facebook developer and have AppID and App Secret

I tried to play from the SDK in C # and looked through a few examples.

It seems like the examples get the user token, but they have to use the browser that is in the windows. This is an automatic process - therefore, I do not want the user to be present.

Ive also created some examples using an application token, but it seems like it cannot write to the wall.

I wrote the Twitter equivalent very quickly. Am I missing something here ???

What is the correct way?

It seems that all I need is: FaceBookClient (appID, appSecret) and then just FaceBookClient.Put (message) ???

clarification added:

Playback using winform application for s # cdk I needed to change their FacebookLoginDialog.cs to use the following 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

which returns a passkey in a WebBrowser.DocumentText

If I call then:

var fb = new FacebookClient(_accessToken); dynamic parameters = new ExpandoObject(); parameters.message = "Hello World!"; dynamic result = fb.Post("me/feed", parameters); 

I get an exception:

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

If I changed the code above to NOT use this access token, but use 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 an exception:

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

I think this is the same exception.

+7
source share
2 answers

Here is what I found.

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

Unzip the code and upload the example CK SDK for Facebook called CS-WinForms to Visual Studio.

At the top of form1.cs - enter your application identifier

Launch the app.

Form1.cs appears using the "Login to Facebook" button. Click the button.

FacebookLoginDialog.cs pops up with a browser window in which facebook is displayed asking for permission.

FacebookLoginDialog.cs creates a browser window that will go to your user in facebook permissions and requests. By default, these permissions are: user_about_me, publish_stream, offline_access.

Offline_access means AccessToken you get - never expires

Click "OK" on Facebook so that the application can access your data on facebook.

FacebookLoginDialog.cs should detect that you are logged in and received an access token that never expires.

An access token is a string.

Paste a breakpoint to copy this access token. Save this access token as you can use it now to access Facebook.

There are some tools on the Facebook developers website that you can use to verify the access token https://developers.facebook.com/tools/debug/access_token You can enter the access token and click "Debug" and it should indicate your identifier applications, UserID, and for "expires" he should say "never."

Once you have this access token, you can simply write code, for example:

  var fb = new FacebookClient(AccessToken); dynamic parameters = new ExpandoObject(); parameters.message = FacebookString; dynamic result = fb.Post("me/feed", parameters); var id = result.id; 

post to facebook!

+3
source

In addition to publish_stream, you should request offline_access. Once you have expired token, save it in your application.

0
source

All Articles