0

我正在使用 Facbook C# SDK v4.0.2,因为那是 Telerik 的 Sitefinity CMS 中包含的内容。我尝试更新,但 Sitefinity 抱怨。

有谁知道 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

3 回答 3

0

我肯定会尝试更新到版本 5。一方面,升级可能会遇到一些小问题,但可以避免使用旧版本时出现更大的问题。

于 2011-04-23T09:04:23.397 回答
0

我最终下载了 4.2 SDK 的源代码,将 AssemblyInfo.cs 中的程序集版本更改为 4.0.2 版本并重新编译。因此,当 Sitefinity 真正使用 4.2 时,我欺骗了 Sitefinity 认为它使用的是 4.0.2 SDK。这完全回避了我最初的问题,但至少现在一切正常。

于 2011-07-26T19:03:03.460 回答
0

我不知道您使用的是 winforms 还是 asp.net,无论哪种方式都尝试使用此 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
于 2011-04-23T13:56:58.237 回答