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

leitor79

Active Member
Licensed User
Longtime User
Hi, Again!

I've been not usint this for a while, and now I'm resuming development.

I want to read a list of friends (those who use the app), and then make a list with name-picture.

I seem to get the list correctly (with FB.CustomRequest("GET", "/me/friends?","friends")), and get the corresponding JSON.

As I haven't implemented the parser yet, I'm trying to get each user information manually (just to check the commands). So, I'm using:

FB.GetFields("1398757477105705",TheFields)
FB.GetFields("1395063697475371",TheFields)
FB.GetFields("1387538914896191",TheFields)

The issue is that the Sub myFB_GetFields_Response(JSONText As String) appears to be executed only once, only for the first request. I get the correct data for the first call, and the Response is never triggered for the second or the third. I think that maybe the requests are triggered to fast... could it be? which would be the correct approach to read the profiles of an array of users? What would you recommend?

Thank you!
 

Douglas Farias

Expert
Licensed User
Longtime User
Why this? the example get diferent facebook id my real is
100000606767838
 

Attachments

  • 11015811_933511910012359_2033675560_n.jpg
    11015811_933511910012359_2033675560_n.jpg
    47.4 KB · Views: 155
  • Sem título.png
    Sem título.png
    128.6 KB · Views: 156

leitor79

Active Member
Licensed User
Longtime User
Hi,

I'm getting some profile info, but now I want to add the birthday from the info I'm getting but I'm not receiving it. On Activity_create I have this:


B4X:
    TheFields.Initialize
    ThePermissions.Initialize
   
    ThePermissions.Add(FB.PERMISSION_USER_FRIENDS)
    ThePermissions.Add(FB.PERMISSION_USER_HOMETOWN)
    ThePermissions.Add(FB.PERMISSION_USER_LOCATION)
    ThePermissions.Add(FB.PERMISSION_FRIENDS_PHOTOS)
    ThePermissions.Add(FB.PERMISSION_USER_PHOTOS)
    ThePermissions.Add(FB.PERMISSION_USER_BIRTHDAY)
    FB.Initialize(Activity,Me, "myFB", AppID, AppSecret, myWebsite )
    FB.LoginWithPermissions(ThePermissions)

    TheFields.AddAll(Array As String(FB.USER_FIELD_ID, FB.USER_FIELD_NAME, FB.USER_FIELD_GENDER,FB.USER_FIELD_LOCATION,FB.USER_FIELD_HOMETOWN,FB.USER_FIELD_BIRTHDAY,FB.USER_FIELD_PICTURE,FB.USER_FIELD_LOCALE))


on myprofile_response, I get the map with the profile info but the birthday is not there...

The question is; do I need to do some reset after adding the new permission? I've logged out, re-logged in (no password is asked, just the facebook's confirm permission window). Am I doing something wrong?

Thank you very much!

PS: I've tried deleting app cache & data, and logging with another fb account (a real one), with same results.
 
Last edited:

Douglas Farias

Expert
Licensed User
Longtime User
maybe you have 2 accounts, one for android development?
nop, later facebook update SDK, this is changed i dont know why.
a time a go i got the correct number 100000606767838, later facebook update all ids change.
i dont use this lib to save facebookid on database, but if any user have used this many time go have problems with db and facebook lib
 

leitor79

Active Member
Licensed User
Longtime User
If the user is not allowing certain fields to show then you won't be able to get them, that depends on their privacy settings.

Hi NJ, thanks for your answer!

The data I'm trying to retrieve it's my own profile... it's possible I'm not allowing myself to get my own info?

It's like the API is not allowing to get some information?

Regards!
 

Mark Thorndyke

Member
Licensed User
Longtime User
Thanks for this NJDude. Working a treat without any hassles. Thankfully easy to adapt an old flash app page to test this with before squirting into my current project. Token sticks on various devices after reboots, which is handy.
Donation will head your way later in the month
 

leitor79

Active Member
Licensed User
Longtime User
Hi,

I'm having an issue with the library.

I have my app log into facebook OK and, at Login_Response, I make a customrequest asking for the user friends who uses the app. I have several test users configured, some of them added as friends among the others, and it works ok.

But, today it happened for the second time (ever; last time was a couple of weeks ago and I thougth I did something wrong); after I log in, instead of showing the website and the activity later, the user profile is shown, like the facebook mobile profile. Name, picture, message saying I have yet fields to complete (where I study, etc), icons on the top (activity, messages, friends), etc. I have an "x" button at top-right, which I use to go back and, apparently, I'm logged.

This is not the problem. The problem is that after that, the test user starts to behave strange. The following customrequest...

FB.CustomRequest("GET","/me/friends?","friends")

...wich until then worked fine, starts to return:

{"data":[]}

(that's the output of Log(JSONText) in customrequest_response)

I've tried changing the loginwithpermissions for login and adding the permissions later, I've cleared data & cache... nothing worked; I have to switch the test user I use to log in in order to get the customrequest working again.

Any ideas?

Thank you very much!
 

analizer3816

Member
Licensed User
Longtime User
NJDude I tested example after april 30,2015 then it shows error after login "Invalid Scope:eek:ffline_access"
I found facebook change permission and remove offline_access
Can you updated new version for remove offline_access?
thanks
 

Petrovic

Member
Licensed User
Longtime User
Is there any update of this library as it don't work anymore. I used it in my Android app to share images to fb, and as I have cca 2500 users that use my app
but now they have a error with fb login and functions. What can I do about this, and I believe I'm not the only one.
Please NJDude or Erel or someone HELP!
 

NJDude

Expert
Licensed User
Longtime User
I have modified the lib and removed the "offline_access" permission, however Facebook has changed again the API so some other things might not work.

On that note, I have to say it: Facebook ALWAYS sucked.
 

ivanomonti

Expert
Licensed User
Longtime User
hi,

hello, I found many mistakes after login type you are unable to post and go over to my profile, attach images :-(
 

Attachments

  • 12204547_998789566851816_1739632007_n.jpg
    12204547_998789566851816_1739632007_n.jpg
    32.7 KB · Views: 154
  • 12231129_998789750185131_2065903710_n.jpg
    12231129_998789750185131_2065903710_n.jpg
    37.5 KB · Views: 137
  • 12242262_998789603518479_520285479_n.jpg
    12242262_998789603518479_520285479_n.jpg
    32.2 KB · Views: 117
  • 12242275_998789770185129_319381309_n.jpg
    12242275_998789770185129_319381309_n.jpg
    32.6 KB · Views: 141
  • 12243909_998789726851800_680453896_n.jpg
    12243909_998789726851800_680453896_n.jpg
    31.7 KB · Views: 132
  • 12244216_998789520185154_1845521737_n.jpg
    12244216_998789520185154_1845521737_n.jpg
    34.6 KB · Views: 127
  • 12248621_998789616851811_348307088_n.jpg
    12248621_998789616851811_348307088_n.jpg
    30.7 KB · Views: 123
  • 12270070_998789596851813_18313075_n.jpg
    12270070_998789596851813_18313075_n.jpg
    33.7 KB · Views: 132
  • 12270292_998789626851810_1184570572_n.jpg
    12270292_998789626851810_1184570572_n.jpg
    44.4 KB · Views: 138
  • 12270439_998789680185138_1151056895_n.jpg
    12270439_998789680185138_1151056895_n.jpg
    35.7 KB · Views: 130

analizer3816

Member
Licensed User
Longtime User
Demo app not update then you must try with facebook and guide.zip+facebook_lib_1.9.zip on first page
now facebok use API 2.3 and 2.5 then old lib cannot post to timeline
 

ivanomonti

Expert
Licensed User
Longtime User
Demo app not update then you must try with facebook and guide.zip+facebook_lib_1.9.zip on first page
now facebok use API 2.3 and 2.5 then old lib cannot post to timeline

sorry I did not understand, the library must be updated from 2.3 to 2.5?
 
Top