2011-05-13 100 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

相關問題