OAuthException not catched with C# FacebookSDK

与世无争的帅哥 提交于 2019-12-08 13:01:52

问题


I try to get my code working with catching certain errors. I store the token for a user after he or she grants permission to my app (this is a WP7 app). When I try to post on the wall by using the stored token it works. When I remove the permissions on facebook it throws an OAuthException. I can't catch it it seems. My app just crashes. This is the code I used:

    private object PostToFacebook()
    {
        _fbApp = new FacebookClient(_appsettings.faceBookToken);

        FacebookAsyncCallback callback = new FacebookAsyncCallback(this.postResult);

        var parameters = new Dictionary<string, object>();
        parameters.Add("message", "message on wall");
        try
        {
            _fbApp.PostAsync("me/feed", parameters, callback);
        }
        catch (Exception ex)
        {

        }
        return null;
    }

    private void postResult(FacebookAsyncResult asyncResult)
    {
        if (asyncResult.Error == null)
        {
            status = "succes";
        }
        else
        {
            status = "error" + asyncResult.Error.Message;
        }
    }

The try catch doesn't catch anything and the generic exception handler in my app.xaml.cs either.

Any ideas how to catch this error so I can ask the user to authenticate again?


回答1:


Put your try..catch in the callback.

You can also catch exceptions globally by handling the UnhandledException event on the App object.



来源:https://stackoverflow.com/questions/5292636/oauthexception-not-catched-with-c-sharp-facebooksdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!