The SD Facebook Button control gives the developer 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, the developer 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 for Smart Devices
- Set the Control Type property with "SD 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 the developer 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 the developer.
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 the developer.
The typical usage of this method is to load the user data in a variable based on SocialUserData SDT using FromJson Method.
This is an informative event that the developer 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 Character based variable called JsonUserData and drag it into the abstract layout of a Panel for Smart Devices.
Then, set its Control Type property with "SD 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.
- Fields renamed as of GeneXus 15 Upgrade 3
As of GeneXus 15 Upgrade 3, those fields associated with the SocialUserData SDT has been renamed.
Those developers who manage previous versions must retrieve the user profile picture by populating the imageUrl field (actual ProfilePicture) as follows:
&UserData.imageUrl = Format(!"http://graph.facebook.com/%1/picture?type=normal&height=300&width=300", &UserData.id.Trim())
Also, the developer can use this formula to get the image in different sizes through three possible values:
- type: Pre-specified sizes (square,small,normal,large)
- height: Image height in pixels.
- width: Image width in pixels.
When height and width are used together the retrieved image will be scaled to approximate it as close as possible.
- Until GeneXus 15 Upgrade 6 FromJson method for SDT is not available on client-side, being necessary to call an online Procedure object for processing it on server-side.
This action can be done as follows:
&SocialUserData = FromJsonProc(&JsonUserData)
Where FromJsonProc procedure executes FromJson method on server-side.
This API is available as from GeneXus 15