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: 775
  • Facebook_Project_And_Guide.zip
    314.1 KB · Views: 1,160
  • Facebook_Lib_1.9.zip
    29.8 KB · Views: 413
Last edited:

Puck

Member
Licensed User
Longtime User
I love this library as I mentioned before. It is the best for Facebook integration since it even works when using gaming libraries.

You can call this a request I guess so one thing that would make it totally complete is if the login page can be cleared or hidden in case the login page is unreachable or some other method. I'll explain.

I've run into a couple of conditions where the login page can get a "page not found" error (internet not reachable do to bad connection). When the page not found happens, it is displayed over my game screen with no way to clear it.

It would be nice if the library cleared the webview if there was a page not found for the login screen or have some way to clear the webview. I'm not sure what the best way to handle this but it is bad when the page times out and displays the webview with the page not found over the top of the game screen. If I have to live with it, it's not a killer. It would be a "nice to have" option to not have this happen.

I do check for an internet connection before calling the fb login which eliminates most of the issue. I can see the problem happening though if the user is in a fringe area with bad or spotty reception. If the fb login page times out, the page not found in the webview is displayed over the top of the game screen.

Maybe you have another way around it. If you have the time, could you tell us a way around this or if it is even possible to get around?

Again, thanks so much for this library. I really appreciate folks like you who provide us with very, very useful tools.
 

NJDude

Expert
Licensed User
Longtime User
I'm currently testing a way to prevent that since it's one issue with WebViews, I'll update the library when I'm satisfied with the results (I'm a control freak, so, wait a little :D)

I didn't include that from the beginning because it's a rare occurrence but I agree, it might be annoying.
 

Douglas Farias

Expert
Licensed User
Longtime User
NJ can you help me?
i need to know a way to get a result of login *-*

for exemple
i need to make only one button to login with facebook
i tryed to make a button with fblogin and getprofile but not work
when i test i press the button the firsth time and i login later i need press again to getmyprofile

i need to make this only one time, make a login and later get a profile can you help me on this?

here a exemple code

sub button_click
FB.Login
FB.GetMyProfile
end sub

Sub myFB_MyProfile_Response(Profile AsMap)
Dim Temp AsString
For I = 0To Profile.Size - 1

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

here i go callsubdelayed(lala, "lala")
End Sub


if you can create a login result go help much for exemple

sub button_click
FB.Login
end sub


sub myfb_loginresul(result as boolean)
if result = true then
FB.GetMyProfile
callsubdelayed(lala,"lala")
else
msgbox("error","error")
end if
end sub

can you make this ? or help me on this? pls pls *-*
i m realy trying but now i really dont know =(
 

Douglas Farias

Expert
Licensed User
Longtime User
yes =( i need to make this

example
B4X:
sub button1_click
fb.login
if login = sucess
fb.getprofile
else
return
end if
end sub


i tryed this

B4X:
sub button1_click
fb.login
fb.getprofile
end sub

this works but
i need to give one click to login, later i need to click again to get profile

its possible you make a fb.login result?

because with this can make

if fb.login.result = true
fb.getprofile
else
msgbox ("error","error")

*-*
 

Inman

Well-Known Member
Licensed User
Longtime User
In my app, in the Main activity there is a "link Facebook" button, clicking on which will open a new activity where the Facebook linking process is done. In that activity, I call fb.login to login and link the user for the very first time. Once this is complete, I want to display a "thank you for linking" message, close this activity and continue with the Main activity.

How can I know when the fb.login process gets finished?

EDIT:
Also, is it possible to implement an fb.login2(scope as string) method where I can specify the &scope= parameter of the oauth request? This is useful when I can mention scope="publish_stream" so that I can login the user and get permission to post to his timeline, in one go, instead of logging in first and then use fb.AddPermission.
 
Last edited:

NJDude

Expert
Licensed User
Longtime User
In my app, in the Main activity there is a "link Facebook" button, clicking on which will open a new activity where the Facebook linking process is done. In that activity, I call fb.login to login and link the user for the very first time. Once this is complete, I want to display a "thank you for linking" message, close this activity and continue with the Main activity.
That could be possible, however, in order to use it you will have to have your own hosting service to host your HTML and display the message you like.

How can I know when the fb.login process gets finished?
There's a way (sort of) but I'd like to test it more to see if it will really work.

EDIT:
Also, is it possible to implement an fb.login2(scope as string) method where I can specify the &scope= parameter of the oauth request? This is useful when I can mention scope="publish_stream" so that I can login the user and get permission to post to his timeline, in one go, instead of logging in first and then use fb.AddPermission.
That's a good idea.

I'll add these suggestions to my To Do list.

Thanks.
 
Last edited:

Inman

Well-Known Member
Licensed User
Longtime User
That could be possible, however, in order to use it you will have to have your own hosting service to host your HTML and display the message you like.

That's ok I have my own hosting. I am looking for some sort of an event like the fb_loginresponse(success as boolean) that will be raised on the completion of login, where success=true if the attempt was successful. I hope you will find a way to implement it.
 

Douglas Farias

Expert
Licensed User
Longtime User
NJ is possible to open only a input in app to log in ?
exemple you press to facebook login and show a input
whats your email later whats your pass
without new activity?
 

tuhatinhvn

Active Member
Licensed User
Longtime User
if i am an user, i will not input any information : email, password facebook to any other app Facebook app

Anyone can make sure can developer not stolen it?
 

Douglas Farias

Expert
Licensed User
Longtime User
make a activity with webview is very slow some time
i think is more fast make a input with user pass and email and send it to a facebook for login *-* is possible?
 

Douglas Farias

Expert
Licensed User
Longtime User
NJ a noob question
how to use this functions? *-*

fb.USER_FIELD_LINK
and many others functions?

have much but i dont know get this.
i tryed to make this a string

for exemple

dim caca as string
caca = fb.USER_FIELD_LINK

this return a msgbox = LINK

can you give me a sample of use this pls?
i m uploaded the images
 

Attachments

  • 10.jpg
    10.jpg
    321.1 KB · Views: 209
  • 20.jpg
    20.jpg
    324.8 KB · Views: 209

Douglas Farias

Expert
Licensed User
Longtime User
sory again *-*
but
dim myFields as ?
and to call this in a mensage box?

msgbox(fb.USER_FIELD_FIRST_NAME ,"test")?
 

Douglas Farias

Expert
Licensed User
Longtime User
I was trying to get the data of the person as
about
https://developers.facebook.com/docs/graph-api/reference/user

I tried
Profile.Get ("about")
but returned null

I found that the value returned fb.USER_FIELD_ABOUT

i tryed this for now


B4X:
                Dim myfields As List
                myfields.Initialize
                myfields.AddAll(Array As String(fb.USER_FIELD_FIRST_NAME, fb.USER_FIELD_LINK))
                Msgbox(fb.USER_FIELD_FIRST_NAME, "My Profile")

but dont return too return null *-*
how can i get about info ?

i m using your example when show a msgbox with Msgbox(Temp, "My Profile")
it dont have about , currency , age_range for exemple how i call this? *-*
 
Top