New Instance of Facebook.component.facebookService hangs

Nov 9, 2008 at 11:28 PM
I have just downloaded v 2.0 of the service and seems great.  I try to perform the sample on the documentation and when I try to create the instance of the service the page just stops processing.

None of the code in the pageload of the sample appears to run.  If I try to debug the project, I get to break at the instance declaration (before the page_load method).  But even if I place a breakpoint at the page_load declaration itself, it never breaks there.  Placing response.writes right after the declaration to see if the app runs at all, nothing, again it doesn't appear to hit it.

Anyone see something like that before.
Developer
Nov 10, 2008 at 2:41 PM
Sounds like the service is having trouble creating a session (which happens before page_load). Can't say I know what the exact problem is off-hand, although sometimes authentication just seems to take a while with Facebook.
Nov 10, 2008 at 3:25 PM
Thanks for the quick reply.  It makes sense what you are saying, but just a couple of more questions, and sorry for the ignorance I will probably display, since I'm new to development for Facebook.

  1. When you mean the service is having trouble creating a session, does that mean with the API-KEY and all of that???  Because the few examples I've seen have the service instantiated at the class level, but the keys are assigned at the page-load event.  If session starts before page-load, would that mean I should put the key definitions at the init level or somewhere else???
  2. There are very few examples out there using this developer kit.  I have only seen a couple of videos and the document example, and they both do EXACTLY the same thing.

Thanks.

Developer
Nov 10, 2008 at 7:39 PM
Exactly which sample are you trying to run?
Nov 10, 2008 at 8:13 PM
I'm using the authorization example from the user's guide (last example):

      Private _fbService As Facebook.Components.FacebookService = New Facebook.Components.FacebookService()

 

      Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

 

            ' ApplicationKey and Secret are acquired when you sign up for

            _fbService.ApplicationKey = "7a399eeba47b0f5b2bfd88cc872ada4a"

            _fbService.Secret = "fad3d3fbeb8571957c39e2792073b978"

            _fbService.IsDesktopApplication = False

 

            Dim sessionKey As String = TryCast(Session("Facebook_session_key"), String)

           

            ' When the user uses the Facebook login page, the redirect back

            ' here will have the auth_token in the query params

            Dim authToken As String = Request.QueryString("auth_token")

 

            ' We have already established a session on behalf of this user

            If (Not String.IsNullOrEmpty(sessionKey)) Then

                  _fbService.SessionKey = sessionKey

                  _fbService.uid = Convert.ToInt64(Session["Facebook_userId"])

            ' This will be executed when Facebook login redirects to our page

            ElseIf (Not String.IsNullOrEmpty(authToken)) Then

                  _fbService.CreateSession(authToken)

                  Session("Facebook_session_key") = _fbService.SessionKey

                  Session("Facebook_userId") = _fbService.uid

                  Session("Facebook_session_expires") = _fbService.SessionExpires

            ' Need to login

            Else

                  Response.Redirect("http://www.Facebook.com/login.php?api_key=" & _fbService.ApplicationKey & "&v=1.0")

            End If

 

            If (Not IsPostBack) Then

                  ' Use the FacebookService Component to populate Friends

                  MyFriendList.Friends = _fbService.friends.GetUserObjects()

            End If
    End Sub

Developer
Nov 11, 2008 at 2:49 PM
This may be a stupid question, but you are trying to run this as an external web app, right? That is, it's its own web page, and it doesn't show up as a part of a Facebook page? The sample you're using is the web application sample, which specifically refers to external web apps. That's why I was asking first about which sample you were using - I had assumed you were using one of the integrated, canvas samples.

If this is an external web app, I'd say your problem doesn't have anything to do with the FDT at all. It looks like nothing is even attempting to load your page. My advice would be to try to remove everything FDT-related from that page, then try to load it. If it still doesn't load , you know it's a problem with something else besides the FDT.
Nov 11, 2008 at 2:55 PM
Hello again, and first let me tell you that I really appreciate you helping me out on this, and I am sorry if I appear to be lost, but that is because I am.

You are right, I am working on an EXTERNAL web app.  More so I have tried this on a web app that I have been building, and on a blank project with nothing else on it but that page.  The last case it is JUST a project with the page that should show the Friends List. When I try to debug the app, I am able to set a break point on the line where I create the instance.  And it works fine.  If I try using the immediate window I get a result from creating the instance.  But then it doesn't even run the page load event.

If I put something else on the page load, and remove all teh FDT stuff, the page_load event triggers fine.  That is why I asked if it could be something with the creation of the instance that just halted everything else.  I do not get any kind of errors.  I have also tried from a server machine on another network (a more public one) that is configured as a server with the same result.
Nov 11, 2008 at 10:34 PM
I'm also running into the same issue when trying out the sample. I'm using C# and creating a webapp. The 'Facebook_userId' session value isn't getting set so I get the following error.

[NullReferenceException: Object reference not set to an instance of an object.]

When I do set the value to my userId, it does work though.  


Developer
Nov 11, 2008 at 11:15 PM
djuang, that doesn't sound like it's the same issue. The Page_Load method isn't even getting called for crg1970, but it sounds like you're getting past that point. If it's a separate issue, I'd prefer to keep that in a different discussion thread.

crg1970, try making your FacebookService a local variable in the Page_Load method instead of an instance variable. So the first few lines of Page_Load should look like this:

       fbService As Facebook.Components.FacebookService = New Facebook.Components.FacebookService()
            ' ApplicationKey and Secret are acquired when you sign up for

       fbService.ApplicationKey = "7a399eeba47b0f5b2bfd88cc872ada4a"

       fbService.Secret = "fad3d3fbeb8571957c39e2792073b978"

       fbService.IsDesktopApplication = False


You can add some printouts/breakpoints/whatever in between all of that, and that will tell you where it's hanging. Either way, at this point if FacebookService really is causing problems, at least you'll see Page_Load getting called. If it still isn't called, it obviously can't be FacebookService, since we haven't done anything with it yet.

From looking at the FDT code, I doubt there's anything there that should cause a problem, but it's worth taking a look.
Nov 11, 2008 at 11:46 PM
Thanks for all your help, don't know why but tha apparently worked.  It connects now and does it's thing.

One last question, and sorry for changing the topic, but if needed I will open that as another discussion.

On the metadata documentation for the methods in the service, there is something I don't understand.  For example if I want to list the user's albums, I can use _fbservice.photos.getalbums(), but the metadata info says that what this method returns is NOT STORAGABLE.  What does that mean??? Can I create a collection and stick the result of that method in it, or not???

Thank you again for all your help!
Nov 12, 2008 at 1:49 AM
jschuster, you're right. i meant to update my post. i wasn't calling 'CreateSession' in the right place in my code. once i rearranged the order in which my application handled authentication, it works fine.

thanks
Developer
Nov 12, 2008 at 3:48 AM
Edited Nov 12, 2008 at 3:48 AM
crg1970, yes, you can do that. Storable parameters have to do with the Facebook Developer terms of service (see http://wiki.developers.facebook.com/index.php/Storable_Information . Basically, you're not allowed to hold onto any data from Facebook for longer than 24 hours. I don't know too much more than that, but that link should be able to tell you more.
Nov 13, 2008 at 8:08 PM
I just wanted to tahnk you all.

The app is now working fine and it was very simple to do once you get going.  Great work on the toolkit. 

Only recomendation would be more server side web controls.  I will try to package some functionality in a few and post them also.  Thanks again!