users.getInfo() API not working

Aug 3, 2009 at 11:38 AM
Hi all,

I am developing an application in facebook using IFrame. I am using users.getInfo() API to get the useinfo. I have following doubts:

1-> Some times this API does not return userInfo. So how should i handle this exception?
2-> Using this API, I am getting only three fields i.e. first name, last name ,name and uid. If i want to get other details like image, about_me, birthday etc. then how will i get those details?

Kindly help.

Thanks and regards,
Aug 4, 2009 at 5:18 AM
Edited Aug 4, 2009 at 5:21 AM

To identify why it doesn't work all the time you need to study about Sessions. Primarily the failure can be analyzed fromt he return value of the getInfo method.

As far as the information about image, about_me is concerned, you need to understand that the call to getInfo restricts some private information which can only be made available if you pass in the active session key. You can get this to work with something similar to this,

Imports facebook
Imports MyListyWrappers

Partial Class _Default
    Inherits System.Web.UI.Page

    Dim facebookObj As New facebook.API()
    Dim userId As Integer

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


            userId = -1
            Dim sessionKeyFound As Boolean = False
            If Request.QueryString("fb_sig_added") = "0" Then
                'User has not added our application. That is, use is not authorized
                'When user is not authorized fb_sig_session_key is never passed

                'So we must enforce user to authorize our application
                facebookObj.ApplicationKey = ConfigurationManager.AppSettings.Get("APIKey")
                facebookObj.Secret = ConfigurationManager.AppSettings.Get("Secret")

                Response.Write("<script language=javascript>parent.location = '" & ConfigurationManager.AppSettings.Get("APIKey") & "&next=" & ConfigurationManager.AppSettings.Get("ServerUrl") & "&canvas=';</script>")

                'Authorized user is accessing the application
                'Identify and proceed only if the session key is found in the Url
                'Each time a user who has authorized your application interacts with it, Facebook will renew the
                'temporary session and send you the session key, even when this user visits a page in your application
                'that(doesn) 't require authorization. You don't need to make any calls to get this key.
                'This parameter isn't passed when an application tab is being requested; fb_sig_profile_session_key is passed instead.
                Dim iframeSessionKey As String = ConfigurationManager.AppSettings.Get("APIKey") & "_session_key"
                If Not String.IsNullOrEmpty(Request.QueryString(iframeSessionKey)) Then
                    Session("SessionKey") = Request.QueryString(iframeSessionKey)
                    sessionKeyFound = True
                ElseIf Not String.IsNullOrEmpty(Request.QueryString("fb_sig_session_key")) Then
                    Session("SessionKey") = Request.QueryString("fb_sig_session_key")
                    sessionKeyFound = True
                    If Not String.IsNullOrEmpty(Session("SessionKey")) Then
                        'Session key found
                        sessionKeyFound = True
                        sessionKeyFound = False
                    End If
                End If

                If sessionKeyFound Then
                    'Also important is
                    'fb_sig_user/fb_sig_canvas_user: The visiting user's ID. fb_sig_canvas_user is passed if user has not authorized
                    'your application, while fb_sig_user is passed if the user has authorized your application.
                    'Neither is passed when an application tab is being requested; fb_sig_profile_user is passed instead.
                    If Not String.IsNullOrEmpty(Request.QueryString("fb_sig_user")) Then
                        userId = Convert.ToInt32(Request.QueryString("fb_sig_user"))
                        If Not String.IsNullOrEmpty(Session("UserId")) Then
                            userId = Session("UserId")
                        End If
                    End If

                    If userId > 0 Then

                        'Fetch the required information against this user
                        facebookObj.ApplicationKey = ConfigurationManager.AppSettings.Get("APIKey")
                        facebookObj.Secret = ConfigurationManager.AppSettings.Get("Secret")
                        facebookObj.SessionKey = Session("SessionKey")

                            Dim userInfoWrapperObj As MyListyWrappers.UserInfoWrapper
                            userInfoWrapperObj = ProjMyListyBusinessLogicObj.GetUserInfo(userId)

'Here you can fetch private data from userInfoWrapperObj as required.

                    End If
                End If

            End If

        Catch ex As Exception
        End Try

    End Sub

End Class


and under web.config file, you can keep the Appliation and Secret keys, similar to ths,

  <add value="99999999999999999999" key="APIKey"></add>
  <add value="99999999999999999999" key="Secret"></add>

Hope that helps.