C#FacebookSDK未捕获OAuthException [英] OAuthException not catched with C# FacebookSDK

查看:54
本文介绍了C#FacebookSDK未捕获OAuthException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使我的代码可以捕获某些错误.在用户授予我的应用程序权限(这是WP7应用程序)后,我为用户存储令牌.当我尝试使用存储的令牌在墙上张贴时,它会起作用.当我删除Facebook上的权限时,它将引发OAuthException.看来我听不懂.我的应用程序崩溃了.这是我使用的代码:

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;
        }
    }

try catch不能捕获任何内容,而我的app.xaml.cs也可以捕获通用异常处理程序.

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?

推荐答案

将try..catch放入回调中.

Put your try..catch in the callback.

您还可以通过处理App对象上的UnhandledException事件来全局捕获异常.

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

这篇关于C#FacebookSDK未捕获OAuthException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆