B4A Library Facebook

catyinwong

Active Member
Licensed User
Longtime User
It is something wrong with your FB app, I used the code you posted and used my info, it works like a charm, I put yours and doesn't work, you are missing a step somewhere.

My FB app is in "development mode". Do I have to go over all the submission process to make it available to public before I can try it in B4A?
 

skaliwag

Member
Licensed User
Longtime User
When I use GetMyPermissions it returns a list such as {"status","permission","status","permission"}, rather than the actual status and permission names. Can this be fixed?
 
Last edited:

Claudio57

Member
Licensed User
Longtime User
Hi NJDude,
in October when I tried the library this worked. Now it does not work. I have not changed anything.
When I try to write a post on the timeline I get the message "Connection Error - Bad Request". Why?

Virtually stopped working in 2015. Until December worked.
 
Last edited:

skaliwag

Member
Licensed User
Longtime User
I don't have any problems with the library, I have apps using it and still work.
NJDude - Have you managed to get any apps using this through Facebook's review?
They have just rejected my app.
It seems they will no longer accept any Android app that does not use the SDK.
 

NJDude

Expert
Licensed User
Longtime User
java.lang.RuntimeException: JSON Object expected.
That means the response from FB is invalid

There is a continuous look that runs on "Log In", can you advise please?
Make sure you entered your credentials correctly, I'm assuming the "Log In", is the progress bar, you will have to close it using ProgressDialogHide.
 

Mashiane

Expert
Licensed User
Longtime User
Hi NJDude, the credentials are fine, tried them and they were working before, for some reason its not now. If your library having a timer that runs continuosly perhaps?
I have also run a loop on the button click to log off the user

B4X:
ProgressDialogShow("Sign Up with Facebook...")
    Do Until fb.IsUserLoggedIn = False
        fb.logout
        DoEvents
    Loop
    fb.Login

This is never stopping execution as I'm still watching the progress bar running. Is there a way to force log out or something?
 

Mashiane

Expert
Licensed User
Longtime User
Hi NJDude, have checked, the version is 1.80, is that correct.

On Sub Globals I have

B4X:
Dim fb As Facebook

On Activity Create, I have

B4X:
fb.Initialize(Activity, Me, "myFB", modJQM.AppID, modJQM.AppSecret, modJQM.appWebsite)

My caller function to Log In

B4X:
Sub cmdRegisterFB_Click
    ProgressDialogShow("Sign Up with Facebook...")
    fb.Login   
End Sub

And my fb_response...

B4X:
Sub myFB_Login_Response(Success As Boolean)
    ' the user has logged in succesfully
    If Success = True Then
        ' we need firstname, lastname and email address
        ProgressDialogShow("Getting your profile...")
        Private TheFields As List
        Private ThePermissions As List
        ' define permissions
        ThePermissions.Initialize
        ThePermissions.Add(fb.PERMISSION_EMAIL)
        fb.AddPermission(ThePermissions)
        ' define the fields
        TheFields.Initialize
        TheFields.Add(fb.USER_FIELD_EMAIL)
        TheFields.Add(fb.USER_FIELD_FIRST_NAME)
        TheFields.Add(fb.USER_FIELD_LAST_NAME)
        TheFields.Add(fb.USER_FIELD_NAME)
        TheFields.Add(fb.USER_FIELD_VERIFIED)
        'TheFields.Add(fb.USER_CONNECTION_PICTURE)
        fb.GetFields("me", TheFields)
        'fb.GetMyProfile
    End If           
End Sub

The rest of it...

B4X:
'Parse the JSON data returned by Facebook
Sub myFB_GetFields_Response(JSONText As String)
    Try
        Private jParser As JSONParser
        jParser.Initialize(JSONText)
        Private Root As Map = jParser.NextObject
        Dim lname As String = Root.Get("last_name")
        Dim fname As String = Root.Get("first_name")
        Dim uemail As String = Root.Get("email")
       
        Log(lname)
        Log(fname)
        Log(uemail)
    Catch
    End Try
    ProgressDialogHide
End Sub

Sub myFB_Facebook_ErrorMessages(Message As String)   
       Msgbox2(Message, "Facebook Error", "Close", "", "", LoadBitmap(File.DirAssets, "exclaim.png"))
End Sub

For some reason ,cmdRegisterFB_Click runs endlessly as the progressbox shows up and hides every second. I dont have any timer in my activity. I have restarted my laptop to no avail? At first, the email address requested shows a null and then shows the correct email on subsequent runs. Kinda stuck...
 

NJDude

Expert
Licensed User
Longtime User
You should use ProgressDialogHide on the error events or success, also, not because you add a permission it means you will get the field(s), the user might have privacy settings to not reveal some fields, like Email for example, you will have to make sure such field is available, and lastly, having an empty CATCH is not good programming, you should either fix or notify the user what's the problem.
 

Mashiane

Expert
Licensed User
Longtime User
Hi NJDude, can you please check this one more time please?

In your attached example here, please include the following code

B4X:
Sub myFB_Login_Response(Success As Boolean)
    ProgressDialogHide
    ' the user has logged in succesfully
    If Success = True Then
        GetProfileButton_Click
        End If
End Sub

This is the endless loop I'm talking about. The "Getting Profile" runs endlessly non stop.
 

NJDude

Expert
Licensed User
Longtime User
I have no issues, I can see the profile, no loops.

By the way I think you meant GetMyProfileButton_Click. I'm attaching the project, just add your credentials.

I would suggest you uninstall and reinstall the app.
 

Attachments

  • TEST.zip
    80.1 KB · Views: 220

Mashiane

Expert
Licensed User
Longtime User
Hi, thanks for the details and sorry for being a pain, I have tried your example and it works perfectly. I noted the GetMyProfile does return the minimum fields I want after all, I will use that instead, I was using GetFields and that has been the cause of my problems and now that I have removed it, it works fine and I no longer have an endless loop. I have reproduced the error on my side by replacing the myFB_Login_Response with this

B4X:
Sub myFB_Login_Response(Success As Boolean)
    ProgressDialogHide
    ' the user has logged in succesfully
    If Success = True Then
        ' we need firstname, lastname and email address
        ProgressDialogShow("Getting your profile...")
        Private TheFields As List
        Private ThePermissions As List
        ' define permissions
        ThePermissions.Initialize
        ThePermissions.Add(fb.PERMISSION_EMAIL)
        fb.AddPermission(ThePermissions)
        ' define the fields
        TheFields.Initialize
        TheFields.Add(fb.USER_FIELD_EMAIL)
        TheFields.Add(fb.USER_FIELD_FIRST_NAME)
        TheFields.Add(fb.USER_FIELD_LAST_NAME)
        'TheFields.Add(fb.USER_CONNECTION_PICTURE)
        fb.GetFields("me", TheFields)
          End If           
End Sub

and also including this

B4X:
Sub myFB_GetFields_Response(JSONText As String)
           Private jParser As JSONParser
        jParser.Initialize(JSONText)
        Private Root As Map = jParser.NextObject
        Dim lname As String = Root.Get("last_name")
        Dim fname As String = Root.Get("first_name")
        Dim uemail As String = Root.Get("email")
       
        Log(lname)
        Log(fname)
        Log(uemail)
    ProgressDialogHide
End Sub

Maybe there was a code piece that I'm doing all wrong. Anyway thanks.
 

NJDude

Expert
Licensed User
Longtime User
Ok, you are making a boo-boo, in your case I would suggest you use "fb.LoginWithPermissions" you then can get the fields if the login is successful.

Look at the attached code.
 

Attachments

  • Corrected.zip
    80.4 KB · Views: 206
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…