2011-05-13 114 views
2

我刚刚从旧的Facebook SDK升级到新的Facebook C#SDK 5.0.25(RTW)。我正在使用一些扩展的权限(如email,read_stream,publish_stream,offline_access)来简单登录我的网站。 (fbWebContext.HasPermission(“email”))...当我这样做时,我得到:Facebook.FacebookOAuthException:(190)无效的OAuth访问令牌签名。“(190)无效的OAuth访问令牌签名”与FacebookWebContext HasPermission

您是否面临这个问题?
下面是我使用的代码:

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")) ... 

有什么不对这种方法?
感谢

回答

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。

+0

感谢您的回答。虽然HasPermission方法抛出异常。我认为问题在于我收到的access_tolken。它最后没有点,而且我所推荐的那个小点也要小。看起来像是我没有完成的交换。 你用什么版本? 你是如何得到acces_tolken的? 再次感谢。 – user751608 2011-05-17 20:47:59

+0

嗨,我刚刚编辑了示例,因此您可以创建一个新页面并将我的代码复制/粘贴到您的Web应用程序中并进行测试。希望你使用.net 4,否则你必须适应“动态我= ...”...我不需要获取访问令牌,C#SDK为我完成这项工作。如果我没有所需的权限,访问令牌将为空。您可以调试并放入手表:FacebookWebContext.Current.AccessToken我使用5.0.25版Facebook.dll:“net40-client”,FacebookWeb.dll:“Facebook.Web.dll” – firepol 2011-05-18 15:26:22

+0

非常奇怪的是,HasPermission方法抛出一个例外。它应该简单地返回true或false。你确定你正在使用一个好的语法? HasPermission只能检查一个权限。 HasPermissions接受更多... – firepol 2011-05-18 15:31:26

相关问题