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:

Inman

Well-Known Member
Licensed User
Longtime User
Excellent! You implemented all the features I was hoping for. Thank you very much.
 

Douglas Farias

Expert
Licensed User
Longtime User
Good Morning
NJ how can i get the profile location when user have this block on the facebook?

when the user have this give error on this code
B4X:
Dim localização as string
Private location As Map = Profile.Get("location" )
localização  = location.Get("name")

i m using login with permissions

B4X:
Dim ListOfPermissions As List
ListOfPermissions.Initialize
ListOfPermissions.AddAll(Array As String( fb.PERMISSION_EMAIL, fb.PERMISSION_USER_ABOUT_ME, fb.PERMISSION_USER_LOCATION,fb.PERMISSION_USER_ABOUT_ME,fb.PERMISSION_FRIENDS_LOCATION))
fb.LoginWithPermissions(ListOfPermissions)


however when there is a user that you have to ask the city happens the error and returns the city, lacking any kind of permição, I added all that I found regarding the city does not even seeking this city these users.
have any idea what might cause this? and how can I apply in the city of all login users?
 

Attachments

  • Sem título.jpg
    Sem título.jpg
    335.3 KB · Views: 209

NJDude

Expert
Licensed User
Longtime User
If you take a look at the sample I posted HERE you will see in line #120 that I capture that error, you will have to do the same, adding a permission will allow you to get whatever field the permission allows to get, but, not necessarily means the user have that field set on his/her profile.
 

Douglas Farias

Expert
Licensed User
Longtime User
realy i see this now, but is possible get the location forced?
put a permission and when the user press OK show hes location?
 

NJDude

Expert
Licensed User
Longtime User
You cannot force it, those are personal preferences the user set on his/her profile, it's your responsibility as a developer to consider all the possible scenarios and write the appropriate code.
 

edwar8405

Member
Licensed User
Longtime User
He encontrado un problema que la librería de Facebook no sé si se pueda solucionar o es algo para definir que beta o de venta. Cuando cambio el packege name del ejemplo de la librería siempre termina por mostrar un error de Connection Error. Please verify you have internet Access. Sin embargo el proceso de autenticación funciona a pesar del mensaje pero no es una buena presentación. Solo está funcionando si el packege name es njdude.facebook.guide

Me podría colaborar con este problema.
 

Attachments

  • Screenshot_2014-04-29-17-01-07.jpg
    Screenshot_2014-04-29-17-01-07.jpg
    296 KB · Views: 197

edwar8405

Member
Licensed User
Longtime User
I found a problem that Facebook library can not know if it is something to fix or define that beta or sale. When I change the name of the packege bookstore example show always ends with error Connection Error. Please Verify You have Internet Access. However the authentication process works despite the message but it is not a good presentation. Is only run if the packege name is njdude.facebook.guide

I could work with this issue.
 

Attachments

  • Screenshot_2014-04-29-17-01-07.jpg
    Screenshot_2014-04-29-17-01-07.jpg
    296 KB · Views: 176

Douglas Farias

Expert
Licensed User
Longtime User
NJ its possible change this mensage for portuguese for exemple?

connection error
Please verify you have internet access
 

Inman

Well-Known Member
Licensed User
Longtime User
Facebook announced Open Graph API 2.0 today, while version 1.0 will expire by April 30th 2015.

https://developers.facebook.com/docs/apps/changelog

In the changelog it is mentioned that apps requesting more than basic_info, email and the user_friends permission must be reviewed by Facebook before those permissions can be requested from people. I used publish_stream permission and so my app will have to go through Facebook's manual review.

In the review submission application, one has to include the step by step process a normal user will undergo when using the Facebook integration (like Click Login button, Wait for the screen, Type your password). When Facebook team realises that I am using the Open Graph API in an Android app, I wonder if they will reject the app and point to use the Facebook Android SDK instead.
 

Douglas Farias

Expert
Licensed User
Longtime User
NJ its possible make when user have a facebook app oficial log on using this
or when in app oficial user is loged on dont need make login in my app?

if user have oficial facebook app only press at login button
else
need login using your lib?
its possible ?
 

tuhatinhvn

Active Member
Licensed User
Longtime User
Can i program to like (or dislike) a post or a photo of my friend (or public posts)?
 

NJDude

Expert
Licensed User
Longtime User
NJ in your example 2 when you take a photo

have a way to take a photo with width and height? for + quality
i need take this photo with 200 x 200

https://developers.facebook.com/docs/graph-api/reference/v2.0/user/picture/

GET /me/picture?redirect=0&height=200&type=normal&width=200 HTTP/1.1Host: graph.facebook.com

have a way?
You have to use GetFields, like this for example:
B4X:
Private TheFields As List

TheFields.Initialize

TheFields.AddAll(Array As String("name", "picture.height(200).width(200)"))

fb.GetFields("me", TheFields)
 
Top