The Facebook Button control gives you public information about the end-user in this social network and helps to log in to/out of Facebook in an easy way, interacting with its native app or requesting through the browser.
In order to use this feature, you must configure the Facebook App Id property.
This control must consolidate the user state information. The steps to incorporate the button are described below:
- Define an attribute or variable based on Character or VarChar data type to catch the JSON string with the user data retrieved from Facebook.
- Drag this attribute or variable from the toolbox to a Panel or Work With object.
- Set the Control Type property to "Facebook Button"
Once finished, two new properties will be available:
- Read Permissions
A set of permissions for retrieved user data separated by commas.
By default, GeneXus asks for public profile information (i.e. public_profile, email, user_friends).
For advanced developers, a complete list of values can be found in Facebook login permissons.
- Publish Allowed
A boolean value to indicate if the app requires publishing permissions.
By default, it's set to False.
Once you sets the button appropriately, new facilities are available to manipulate the user data retrieved from Facebook.
It encapsulates the user data retrieved from Facebook. It is enabled once the SD Facebook Button control is detected.
Note: If SocialUserData does not have this structure, please download and import this patch in your Knowledge Base.
A set of events is available to catch the relevant information for you.
All of the events accept input parameters.
This is the first event called after the end-user starts a new Facebook session (async process). Once it's finished and the connection has been established, the user information is updated and available to you.
The typical usage of this method is to load the user data in a variable based on SocialUserData SDT using Business Component FromJson method.
This is an informative event that you can use to update some indication of the state of the current Facebook session.
In this event, the user information is not updated yet. Try to avoid it to deserialize the user information because you can have outdated information.
This is an informative event that indicates when the user logged out of the Facebook session.
This event retrieves the Facebook default error when something goes wrong during the authentication process.
This event is appropriate if you want to show a custom error when something goes wrong.
First, define a variable called JsonUserData based on the Character data type and drag it into the abstract layout of a Panel object.
Then, set its Control Type property to "Facebook Button" value and note the new two properties displayed.
Also, the variable in the layout changes its appearance (is not shown as a text field).
After that, define a new variable based on UserSocialData SDT (in this case is called SocialData). Then proceed to write an event to load it and say hello to our user.
Finally, the result in runtime is shown below.