“(190)无效的OAuth访问令牌签名”与FacebookWebContext HasPermission

时间:2011-05-13 00:59:09

标签: facebook-c#-sdk

我刚从旧的facebook sdk升级到新的Facebook C#SDK 5.0.25(RTW)。我正在使用一些扩展权限(例如email,read_stream,publish_stream,offline_access)轻松登录我的网站。

一切正常,直到我检查权限:if(fbWebContext.HasPermission(“email”))...当我这样做时,我得到:Facebook.FacebookOAuthException:(190)无效的OAuth访问令牌签名。

你是否面临这个问题? 以下是我正在使用的代码:

JS:

    FB.login(function (response) {
        if (response.session) {
            if (response.perms) {
                // user is logged in and granted some permissions.
                // perms is a comma separated list of granted permissions
            } else {
                // user is logged in, but did not grant any permissions
            }
            window.location.reload();
        } else {
            // user is not logged in
        }
    }, { perms: 'email,read_stream,publish_stream,offline_access' });

C#:


        var fbWebContext = FacebookWebContext.Current;

        if (fbWebContext.IsAuthorized())
        {
            var permissions = new FacebookWebAuthorizer(fbWebContext).Permissions;
            if (fbWebContext.HasPermission("email")) ...

这种方法有问题吗?
感谢

1 个答案:

答案 0 :(得分:0)

我使用不同的方法:

我没有为FacebookWebContext声明一个新变量。 我不检查是IsAuthorized(对我而言,它在应用程序中给出了一些问题)。

所以,如果我是你,我会尝试以下内容,其中还包括一个授权请求,以防用户以前没有授予权限。希望这会有所帮助。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Facebook.Web;

namespace FacebookCsharpDemo
{
    public partial class askPerm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (FacebookWebContext.Current.HasPermission("email"))
            {
                //permissions given
                processEmail();
            }
            else
            {
                var auth = new CanvasAuthorizer { Permissions = new[] { "user_about_me", "email" } };

                if (auth.Authorize())
                {
                    processEmail();
                }
                else
                {
                    //show permissions error message - not really - facebook c# sdk will redirect the user to the cancelUrlPath defined in the web.config...
                    litEmail.Text = "You must authorize the Application, please try again";
                }

            }

        }

        private void processEmail()
        {
            var fb = new FacebookWebClient();
            dynamic me = fb.Get("me");

            litEmail.Text = me.email;
        }

    }
}

在.aspx页面中只输了一个名为litEmail的文字。

相关问题