Facebook SDK Wrapper + Native Facebook LoginButton

Douglas Farias

Expert
Licensed User
Longtime User
aaaah_FIM_DE_SEMANA.gif
 

Periklis Koutsogiannis

Active Member
Licensed User
Longtime User
Update: 1.52

Updated files: facebook.zip [wrapper: YES samples: YES]

  • Added: Facebook.JustDisconnected
How to use FB.JustConnected,Facebook.JustDisconnected and Facebook.Me:

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

    Public FB As Facebook
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Dim CurrentActivity As FacebookActivity
End Sub

Sub Activity_Resume
    FB.SetActivity(CurrentActivity.Initialize("facebook_statuschanged_event"))
End Sub

Sub facebook_statuschanged_event
    'Access FB public properties and update UI accordingly when session changes

    If FB.JustConnected Then 'JustConnected property will be set to true only when connected once
        Msgbox(FB.Me, "JustConnected!") 'FB.Me is a Map object that contains all user details
    End If

    If FB.JustDisconnected Then 'JustDisconnected property will be set to true only when disconnected once
        Msgbox("Bye bye!", "JustDisconnected!")
    End If
End Sub
 
Last edited:

Periklis Koutsogiannis

Active Member
Licensed User
Longtime User
Update: 1.53

Updated files: facebook.zip [wrapper: YES samples: YES]

  • Added: Facebook.GetFeed,Facebook.GetComments, Facebook.GetComment, Facebook.GetLikes, Facebook.GetGraphObject, Facebook.DeleteGraphObject
 
Last edited:

brelto85

Active Member
Licensed User
Longtime User
Hi!
another question
In my app, i allow to user to connect via facebook from preference activity
subsequently, there's a functionality in the app that allows to upload a photo using the command voice
my goal is to connect the user and add the publish permission during the login phases, not before the upload method

if i write this lines code

B4X:
Common.mFB.Login(Array As String ("email"))
Common.mFB.RequestPublishPermissions

the permission page do not show
what is the best way to do that?
 

Periklis Koutsogiannis

Active Member
Licensed User
Longtime User
Have you set the activity with Common.mFB.setActivity ?

Everything that has visuals in the SDK must have an activity handle referenced.

I am not familiar with preference activities yet, so can you please show me the initialization part of your preference activity? Does it have a Globals, Activity_Create or Activity_Resume?
 
Last edited:

Periklis Koutsogiannis

Active Member
Licensed User
Longtime User
Sorry, I misunderstood you.

The login phase is the only asynchronous action.

That means that you have to catch the login in the event and when Common.mFB.JustConnected is true, call Common.mFB.RequestPublishPermissions

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Dim CurrentActivity As FacebookActivity
End Sub

Sub Activity_Resume
    Common.mFB.SetActivity(CurrentActivity.Initialize("facebook_statuschanged_event"))
End Sub

Sub facebook_statuschanged_event
    If Common.mFB.JustConnected Then
        Common.mFB.RequestPublishPermissions
    End If
End Sub
 
Last edited:

Periklis Koutsogiannis

Active Member
Licensed User
Longtime User
You may also check before calling Common.mFB.RequestPublishPermissions if the publish_actions permission is already included in the Common.mFB.Permissions property and exclude this step (means that the user has already granted publish permissions).
 
Last edited:

Periklis Koutsogiannis

Active Member
Licensed User
Longtime User
Update: 1.6

Updated files: facebook.zip [wrapper: YES samples: YES]

  • Fix: Fixed a bug that prevented requests from being canceled properly.
  • Change: Complete code refactoring. Now using the new shared SocialApiWrapper library that provides common functionality to all SDK wrappers

How to migrate from previous versions:
  1. Select the SocialApiWrapper library from the list of the available libraries in the IDE along with the Facebook library.
  2. Change all FacebookActivity types in your projects to WrapperActivity
Done!
 
Last edited:

brelto85

Active Member
Licensed User
Longtime User
Hi, i've notice that if there isn't the internet connection, show up the toast message "unable to resolve host ..... graph.facebook ...."
Is possible to prevent the toast or i must check internet connection?

in addition i've notice if there isn't a internet connection and call a Login method, return a NullPointerException error:

java.lang.NullPointerException
at com.datasteam.b4a.facebook.Facebook.internalLogin(Facebook.java:197)
at com.datasteam.b4a.facebook.Facebook.Login(Facebook.java:221)
at com.breltolab.drivi.activitypreference._swfb_checkedchange(activitypreference.java:791)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:162)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:158)
at anywheresoftware.b4a.objects.SwitchWrapper$1.onCheckedChanged(SwitchWrapper.java:39)
at android.widget.CompoundButton.setChecked(CompoundButton.java:126)
at android.widget.Switch.setChecked(Switch.java:677)
at android.widget.CompoundButton.toggle(CompoundButton.java:87)
at android.widget.CompoundButton.performClick(CompoundButton.java:99)
at android.view.View$PerformClick.run(View.java:17085)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5454)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
at dalvik.system.NativeStart.main(Native Method)
 
Last edited:

Periklis Koutsogiannis

Active Member
Licensed User
Longtime User
Will be fixed in the next version. Also, if there is a connection error, it will propagated through the FacebookResult object and there will be not toast :)
 

Periklis Koutsogiannis

Active Member
Licensed User
Longtime User
Update: 2.0
  • Now part of the SocialApi unified wrapper library
  • Major code refactoring (again)
  • Renamed: Facebook -> FacebookProvider
  • Renamed: WrapperActivity -> SocialApiActivity
  • Renamed: WrapperActivity.Initialize -> SocialApiActivity.GetWithEvent
  • Added: FacebookProvider.GetAppFriends, FacebookProvider.GetFriends, FacebookProvider.GetTaggableFriends

How to migrate from previous versions:
  1. Delete Facebook.jar SimpleApiWrapper.jar and Facebook.xml SimpleApiWrapper.xml from your B4A Libraries folder
  2. Select the SocialApi library from the list of the available libraries in the IDE
  3. Rename all mentioned classes in the change log above
Done!
 
Last edited:

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hi Periklis

Firstly as huge congrats on the work you have done here. You should receive a B4A Community Achievement award (If such a thing existed). I have downloaded all the necessary components and have been playing with FB sample 1. WOW !!!

My question is; In my app the user will store their social network login details. I then want to seamlessly connect to say FB and do the login do a post and then log-out without the user having to interact with any login screens. Is this possible ?

Thanks again for providing your socialAPIwrapper :)

Regards

John.
 

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hi

How do we check if we have postable permissions so we do not need to request them each time our app loads.

Regards

John.
 

GMan

Well-Known Member
Licensed User
Longtime User
Hoi Perikles,

as NJDude also published a Facebook lib with the same name, we might get in trouble when copying them to the lib directories.
Isnt there a list with the native names of the libs (for lib developers) ?
 

Periklis Koutsogiannis

Active Member
Licensed User
Longtime User
@Jmu5667, Thank you!

Facebook SDK does not allow automatic login. It only keeps the session cached so that the user does not need to type in the credentials again. You may request offline_access permissions to use the users access_token and publish on his behalf but it is not implemented yet. Also, you can check the FacebookProvider.Permission property to see what permissions are already granted.

@GMan, yo :) ... Get the latest socialapi 2.0 where all names are changed. See the last changelog
 

Periklis Koutsogiannis

Active Member
Licensed User
Longtime User
Update: 2.1

  • Changed: GetPhotos, GetAlbums have an extra parameter UserId. Leave it blank to access your own profile.
 
Top