How to login?

Jul 24, 2009 at 10:45 AM

I can't figure out how to authenticate. What I understood so far is:

FacebookDataContext requires that its internal API class has the following 4 parameters filled in: ApplicationKey, Secret, AuthToken and SessionKey.

I get the first two from my developer page. The other two sound like something dynamic you get after loggin in on facebook.


What I can't find in this project is a straightforward way to login. I mean, something like

AuthParams Login(string Username, string Password)

This sends my credential to facebook, and if valid, returns an instance of AuthParams, which contains AuthToken and SessionKey.


Even if not this straightforward, how do I get AuthToken and SessionKey without opening a browser and putting the credentials manually? I am building a DLL so there's no way authentication requires user input.



Jul 26, 2009 at 9:14 AM


You cannot send any credentials to Facebook, for security reasons, only Facebook can authenticate the user. You need to send your user to the facebook login page with some parameters, and after a successful authentication, the user will be redirected back to your app, with the missing parameters. I've created a helper class to help you do this automatically in the library, to use it, simply add this line in your Page_Load handler on your main .aspx page:



var fb = new FacebookDataContext();

        //TODO: access Facebook as an authenticated user

You can find some nice online code examples here:

If you have any more questions please don't hesitate to ask.





Jul 27, 2009 at 8:22 AM

Thank you for your explanation.

I actually find this restriction from Facebook rather stupid. I am developing a website for a music band, and in the administrative panel I intented to provide them a simplified interface with a textbox and a send button which would simoultaneously post their message con facebook, twitter, etc.

I would store their authentication in the web.config so they don't have to input it every time. It works for twitter, too bad I can't do that for Facebook. I guess I'll give up on my idea.

Jul 27, 2009 at 8:36 AM

This restriction helps preventing third party websites from collecting and storing facebook usernames and passwords. Many large service providers use this techinique, PayPal, Amazon, etc...

You might want to read some more on facebook Connect, although i don't think it has the answer you're looking for, it might give you some alternative.

Good luck :-)