SD Facebook Button control

Official Content
This documentation is valid for:

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.

Adding the button

This control must consolidate the user state information. The steps to incorporate the button are described below:

  1. Define an attribute or variable based on Character or VarChar data type to catch the JSON string with the user data retrieved from Facebook.
  2. Drag this attribute or variable from the toolbox to a Panel or Work With for Smart Devices
  3. 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.

Facilities

Once the developer sets the button appropriately, new facilities are available to manipulate the user data retrieved from Facebook.

Structured Data Types

SocialUserData

It encapsulates the user data retrieved from Facebook. It is enabled once the SD Facebook Button control is detected.

SocialUserData
{
    Id: Character(20)
    Name: Character(20)
    FirstName: Character(20)
    MiddleName: Character(20)
    LastName: Character(20)
    ProfileName: Character(20)
    ProfileImage: Image 
    Gender: Character(100)
    Birthday: Character(20)
    Country: VarChar(40)
    City: VarChar(40)
    Email: Email
    LocationLatitude: Character(20)
    LocationLongitude: Character(20)
}

Note: If SocialUserData does not have this structure, please download and import this patch in your knowledge base.

Events

A set of events is available to catch the relevant information for the developer.
All of the events accept input parameters.

OnUserInfoUpdated

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.

OnUserLoggedIn

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.

OnUserLoggetOut

This is an informative event that indicates when the user logged out of the Facebook session.

OnError

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.

Example

First, define a Character based variable called JsonUserData and drag it into the abstract layout of a Panel for Smart Devices.

SD Facebook Button - Layout

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).

SD Facebook Button - Properties

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.

SD Facebook Button - Add event

Event &JsonUserData.OnUserInfoUpdated
    Composite
        &SocialData.FromJson(&JsonUserData)
        msg(Format("Hello %1!",&SocialData.name))
    EndComposite
Endevent

Finally, the result in runtime is shown below.

Android device
SD Facebook Button - Runtime (Android)

iOS device
SD Facebook Button - Runtime (iOS)

Considerations

  • 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.

    Rules
    parm(in:&JsonUserData, out:&SocialData);
    Source
    &SocialData.FromJson(&JsonUserData)

Scope

Objects Panel for Smart Devices, Work With for Smart Devices
Data type Character, VarChar
SD Generators iOS, Android
Languages .NET, Java

Availability

This API is available as from GeneXus 15




Was this page helpful?
What Is This?
Your feedback about this content is important. Let us know what you think.