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:
Code: Copy
'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

Last edited:
Trying to wrap fb object and all fb code (login,posttotimeline,fb events) in a class. When initing fb with
fb.initialize(activity,me,...) it would not compile.
Also will not compile with
fb.initialize(main,me...)

Any advice?
 
uploading works and posting however it keeps hanging in the screen that "uploading to facebook" status.. Even if the picture is already uploaded. How to check if the uploading is done????
 
Is possible to use this library to post / upload image in a especific friend wall?
 
Use any of these 2 events accordingly: PostToTimeline_Response or UploadToTimeline_Response.

I am using this way:
Code: Copy
Sub myFB_UploadToTimeline_Response(PictureID As String)
    'Save the most recent post to delete it later
    PostToDeleteID = PictureID

    'hide the progress dialog
    ProgressDialogHide           
End Sub

It's Ok or there are other method to check if upload is done and hide the progressdialog?
 
It doesn't work. When I ran it and clicked the Login button, it popped out an error message (Invalid or missing AppID/AppSecret, Missing client_id parameter) but i have already typed all the info... can anyone help???
 
That means the information you entered is missing or incorrect. Have you followed the instructions in the quick guide?

Thanks a lot. I checked and found the error was because I misplaced the library in the libraries folder instead of the additional libraries folder.. But another error popped up, saying that "The parameter redirect_url is required". But it was the same with that one in the Facebook app... Why is there the error??
 
Thanks a lot. I checked and found the error was because I misplaced the library in the libraries folder instead of the additional libraries folder.. But another error popped up, saying that "The parameter redirect_url is required". But it was the same with that one in the Facebook app... Why is there the error??
Double check your settings, also, male sure there's no redirection or the validation will fail.
 
Double check your settings, also, male sure there's no redirection or the validation will fail.
I have checked and cannot find the reason by myself. T^T

These are all my info..
App ID: 1656383324589325
App Secret: f0487c213728c360a8971ba06994d460
URL: http://www.catlingdnt.com/

upload_2015-2-1_4-39-26.png
 
If you have entered the URL exactly as you have it on FB it should work.

One thing though, now you will have to create a new FB app, the App ID and App Secret should NOT be published unless you want your app to be hacked :D

I have entered exactly the same. That's why I am asking for help.....
I know that. The FB app is only for testing, I will delete it after I have tried it working anyway so it doesn't matter. :)
upload_2015-2-1_4-55-37.png
 
If you go to SETTINGS -> ADVANCED, under SECURITY you should see "Valid OAuth redirect URIs" do you have the link to your site there?
Yes. BTW do I need the Client Token for anywhere?
 

Attachments

  • upload_2015-2-1_5-1-27.png
    upload_2015-2-1_5-1-27.png
    176.6 KB · Views: 506
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.
What should be missed? There isn't much about the fb app setting in this thread so I simply followed other threads which I searched. Maybe I was following one incompleted or outdated??
 
Back
Top