2011-04-22 56 views
0

我正在使用Facbook C#SDK v4.0.2,因爲這是Telerik的Sitefinity CMS中包含的內容。我嘗試更新,但Sitefinity抱怨。與Facebook的空會話C#SDK 4.0.2

有誰知道v4.0.2是否仍然有效?我使用FB JS SDK和<fb:login-button/>登錄,並且能夠通過JavaScript查詢API。當我嘗試使用C#SDK時,我總是得到(new FacebookApp).Session == null。我在一個webforms應用程序中使用了SDK,但我要脫離的示例來自SDK的MVC示例。

SDK MVC例如:

public ActionResult Profile() 
    { 
     var app = new FacebookApp(); 
     if (app.Session == null) 
     { 
      // The user isnt logged in to Facebook 
      // send them to the home page 
      return RedirectToAction("Index"); 
     } 

     // more example code ... 
    } 

我在做類似的事情:

var app = new FacebookApp(); 
    if (app.Session != null)  
    { 
     FormsAuthentication.SetAuthCookie(user.UserName, false);  
    } 
    else 
    { 
     //user is logged in to facebook but has not registered. 
     response.Redirect("register.aspx?needsFacebook=1", true); 
    } 

是v.4.0.2還有效嗎?如果用戶使用Facebook進行身份驗證,這是我應該檢查服務器的方式嗎?

回答

0

我結束了下載的來源爲4.2 SDK,改變的AssemblyInfo.cs裝配版本4.0.2版本並重新編譯。因此,我欺騙Sitefinity認爲它在使用4.2時使用4.0.2 SDK。這完全迴避了我原來的問題,但至少現在一切正在開展。

0

我肯定會嘗試更新到版本5.一方面,您可能會遇到一些小問題升級,但您可以避免使用舊版本時出現更大的問題。

+0

我想升級,但我的CMS - Sitefinity - 是建立在4.0.2和使用SDK的升級版本時拋出的錯誤。您是否使用過Sitefinity併成功升級了FB SDK程序集? – Jeff 2011-04-25 14:38:06

0

如果你正在使用的WinForms或asp.net,無論哪種方式,嘗試使用this API代替,看看是否能解決您的問題,我不能告訴。它應該只花你幾分鐘的時間來確定它是否有效。

爲了驗證你會做的WinForms如下:

時,單擊窗體上的按鈕,這將驗證用戶。

Imports Branches.FBAPI 
... 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
Dim SI As New SessionInfo("[application_id]","applicaiton_secret") 
    ' Add an event handler so that you can process 
    ‘ the response when the user is authenticated 
    AddHandler SI.AuthenticationResult, AddressOf ReadResponse 
    ' Call the function to display a form to the user and log them into Facebook 
    SI.AuthenticateUser(Me, False) 
End Sub 

當過程完成時,會觸發事件調用ReadResponse幷包含與所有其他認證步驟中相同的響應對象。

Sub ReadResponse(ByVal FBR As Branches.FBAPI.SessionInfo.FacebookResponse) 
    Label1.Text &= " - " & FBR.UserID 
    Me.BringToFront() 
End Sub 
+0

我使用自帶與Facebook C#SDK 4.0.2預包裝一個CMS(稱爲Sitefinity)。如果我不必和Sitefinity拋出每個頁面請求的錯誤,如果我嘗試升級FB組件我寧願沒有引入另一個庫。 – Jeff 2011-04-25 14:40:32