与Facebook的空会话C#SDK 4.0.2
我正在使用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进行身份验证,这是我应该检查服务器的方式吗?
我结束了下载的来源为4.2 SDK,改变的AssemblyInfo.cs装配版本4.0.2版本并重新编译。因此,我欺骗Sitefinity认为它在使用4.2时使用4.0.2 SDK。这完全回避了我原来的问题,但至少现在一切正在开展。
我肯定会尝试更新到版本5.一方面,您可能会遇到一些小问题升级,但您可以避免使用旧版本时出现更大的问题。
如果你正在使用的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
我使用自带与Facebook C#SDK 4.0.2预包装一个CMS(称为Sitefinity)。如果我不必和Sitefinity抛出每个页面请求的错误,如果我尝试升级FB组件我宁愿没有引入另一个库。 – Jeff 2011-04-25 14:40:32
我想升级,但我的CMS - Sitefinity - 是建立在4.0.2和使用SDK的升级版本时抛出的错误。您是否使用过Sitefinity并成功升级了FB SDK程序集? – Jeff 2011-04-25 14:38:06