I am currently using Facebook's C # SDK v4.2.1, and I'm trying to post something to the user's wall. It worked fine until it received a FacebookOAuthException (OAuthException) Error validating access token. , and I cannot catch this exception, and this will cause my application to crash.
I use this call FacebookApp.ApiAsync("/me/feed", ...) . Since this is happening async, I'm not sure where I have to put my try-catch block in order to catch this error, but without success
This is what I use:
private void shareFBButton_Click(object sender, System.Windows.RoutedEventArgs e) { // ... code for preparing strings to post ... try { // setup FacebookApp and params ... app.ApiAsync("/me/feed", args, HttpMethod.Post, (o) => { if (o.Error != null) { Debug.WriteLine("ERROR sharing on Facebook: " + o.Error.Message); } else { Debug.WriteLine("FB post success!"); } }, null); } catch (Exception ex) { Debug.WriteLine("ERROR sharing on Facebook: " + ex.Message); } }
So can someone tell me where should I put my try-catch block so that I can catch an OAuthException ?
EDIT:
After further investigation, FacebookOAuthExcpetion is thrown out of the Facebook SDK CK after the SDK catches WebException and FacebookApiException. For more information, see "Pavel Surmenok." This is exactly what is happening.
Right now, the only solution to catching FacebookApiException (the base class of all SDK exceptions for Facebook) is the trick in the App.UnhandledException method. Check the type of e.ExceptionObject and if it is set to FacebookApiException, e.Handled to true and the application will no longer exit.
source share