Facebook-C#-SDK wont stop "logging in"

461 views Asked by At

I am trying to build a facebook WebApp in vb.net using the Facebook C# SDK. The SDK can be used for vb.net, this I know. However I am trying to get my app to login on page load. I can get it to login, however my app does not recognize that it is logged in and continues to loop through the login again until i stop it. Here is my code.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim faceauth As New FacebookClient
    Dim fbsession As New FacebookSession
    If faceauth.AccessToken.Length = 0 Then
        Dim appId As String = ConfigurationManager.AppSettings("facebookappid")
        Dim extendedPermissions As String() = {"publish_stream", "offline_access", "read_stream", "manage_pages"}
        Dim oauth = New FacebookOAuthClient() With { _
         .ClientId = appId _
        }
        fbsession.Expires = Now.AddDays(1)
        Dim parameters = New Dictionary(Of String, Object)() From { _
         {"response_type", "code_and_token"}, _
         {"display", "popup"}, _
         {"redirect_uri", "http://newsocialspin.spintest.com/fbcsb.aspx"} _
        }
        If extendedPermissions IsNot Nothing AndAlso extendedPermissions.Length > 0 Then
            Dim scope = New StringBuilder()
            scope.Append(String.Join(",", extendedPermissions))
            parameters("scope") = scope.ToString()
        End If
        Dim loginUrl = oauth.GetLoginUrl(parameters)
        Response.Redirect(loginUrl.ToString)
    Else
        LoggedIn()
    End If
End Sub

I have tried countless different methods to get it to recognize the logged in status to no avail. If you have any ideas that would be helpful please let me know, or if your a dev please correct my obvious error. Thanks.

2

There are 2 answers

0
Harper Shelby On BEST ANSWER

You're creating a new FacebookClient on every page load, including the redirected ones. Thus, your check on faceauth.AccessToken.Length is always true. You'll need to have some cookie or session value that will survive the redirects, and get updated appropriately when you log in via Facebook.

0
Kon On

Take a look at this discussion that helped me. Basically you need to make sure that you are running the latest version of the SDK and that Facebook app is properly configured to leverage a signed request (which of course you have to supply).