B4A Library Facebook

This library will allow your apps to interact with Facebook.


Requirements:

1- B4A 3.x

2- Facebook account.

3- Copy the Facebook.xml and Facebook.jar to your additional libraries directory.


Usage:
B4X:
'Initialize the library
Dim FB As Facebook

'Get the following 3 fields from Facebook after creating a Facebook app.
Dim AppID As String = "<APP_ID_FROM_FACEBOOK>"
Dim AppSecret As String = "<APP_SECRET_FROM_FACEBOOK>"
Dim myWebsite As String = "<LINK_TO_THE_WEBSITE_IN_REDIRECT_URI>"

FB.Initialize(Activity, Me, "myFB", AppID, AppSecret, myWebsite)

'Login to Facebook
FB.Login

'Get your profile
FB.GetMyProfile

...

'Display profile fields
Sub myFB_MyProfile_Response(Profile As Map)

    Dim Temp As String

    For I = 0 To Profile.Size - 1

        Temp = Temp & Profile.GetKeyAt(I) & ": " & Profile.GetValueAt(I) & CRLF

    Next

    Msgbox(Temp, "My Profile")


End Sub

The attached files contain:

a- The Facebook library.

b- "How to create a Facebook app" quick guide.

c- A sample project.


NOTES: You have to have some basic knowledge of the Facebook API to use it, especially about permissions, the library allows you to interact with Facebook but you are responsible to add/remove the necessary permissions for the actions you want to perform.

You have to create a Facebook app before you can use the library, the instructions are in the quick guide mentioned on item "b" above.


A DEMO app (apk) is also attached for you to take a look at the library's functionality.

Library recompiled on May 28, 2017 (B4A 6.8+)
 

Attachments

  • FacebookDemoApp.apk
    231.9 KB · Views: 776
  • Facebook_Project_And_Guide.zip
    314.1 KB · Views: 1,161
  • Facebook_Lib_1.9.zip
    29.8 KB · Views: 414
Last edited:

leitor79

Active Member
Licensed User
Longtime User
I've used this library a long ago, maybe I don't remember much, but I remember having issues (I don't know if issues like yours) involving facebool two-step verification and/or authorized devices in your facebook account.

Regards!
 

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
OK.. I will try again.

Another question, please: How I can get the user email?

i put like this in my code:

Dim ListOfPermissions As List
ListOfPermissions.Initialize
ListOfPermissions.AddAll(Array As String(fb.PERMISSION_EMAIL))
fb.LoginWithPermissions(ListOfPermissions)

And when GetMyProfile I don´t have this field....

Thanks
 

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
don´t worry.!! I got now.

I call this:

B4X:
    Dim lstFields As List
    lstFields.Initialize
    lstFields.AddAll(Array As String(fb.PAGE_FIELD_NAME,fb.USER_FIELD_EMAIL))
    fb.GetFields(strID,lstFields)


B4X:
Sub myFB_GetFields_Response(JSONText As String)
      Log("[myFB_GetFields_Response]:" & JSONText)
End Sub

{"name":"my name from facebook","email":"myemail\u0040hotmail.com","id":"11222333444"}


Now it´s working! Thanks
 

analizer3816

Member
Licensed User
Longtime User
@NJDude, can you add video uploading feature?
because facebook allow this.
or if facebook lib1.9 can do it, please tell me.

thanks in advanced
 

Smee

Well-Known Member
Licensed User
Longtime User
Is it possible to post to a group of which I am a member
 

Smee

Well-Known Member
Licensed User
Longtime User
Thanks for a great library. I have a small problem. I want to test if a user is logged in so I use "If FB.IsUserLoggedIn Then" which is fine when they are logged in but it seems it also returns true if they are logged in on the device but not in the app.

I tried to overcome this by running "FB.GetMyProfile" and trapping for an error. The Sub myFB_Facebook_ErrorMessages(Message As String) fires on the error but i have no way to dismiss it so I get a crash

(Exception) Not initialized
java.lang.NoSuchMethodError: anywheresoftware.b4a.keywords.Common.Msgbox2
at njdude.facebook.sample.facebook._hc_responseerror(facebook.java:1790)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at anywheresoftware.b4a.BA$2.run(BA.java:360)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
--------- beginning of /dev/log/system

I realise I could just log in first but I give the user the option of a google login or a facebook one.
Is there any way to overcome this?

Many thanks?
 

Smee

Well-Known Member
Licensed User
Longtime User
This library doesn't interact with the FB app so it won't be possible.

Thanks for the reply. I am not sure I understand what you mean it "doesn't interact with the FB App" . Do you mean that it just does not interact with Facebook? Does it also mean that the crash cannot be avoided?
 
Top