I do this:
// Note: FbApp is set outside of this code (var FbApp = new FacebookApp();)
if (string.IsNullOrEmpty(FbApp.AccessToken)) {
var oauthClient = new FacebookOAuthClient() {
AppId = FbApp.AppId, AppSecret = FbApp.AppSecret,
RedirectUri = new Uri("http://www.mysite.com/")
};
dynamic sessionData = FbApp.Session.Data;
string code = sessionData.code;
dynamic result = oauthClient.ExchangeCodeForAccessToken( code );
FbApp.AccessToken = result.access_token;
}
I get a “(OAuthException) Error validating verification code.” message. The RedirectUri setting is set to the same setting as on the Facebook Apps page (with trailing slash). The AppId and AppSecret are correct.
It seemed to work against my test app, on my dev box. Once I uploaded the code to production, and switched to live app (on Fb), it started acting this way (the .ExchangeCodeForAccessToken() doesn’t want to work correctly).
Am I doing it wrong? 🙂
Well, it turns out I was trying harder than I needed to (plus it appears FacebookApp is being deprecated).
If you need to check if a user is authenticated (with token safety), just do this:
FacebookWebContext.Current.IsAuthenticated(). Done. Very nice SDK guys, I really dig it.