ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Communication / Facebook functions
  • Overview
  • Elements available in WLanguage
  • Registering the application on Facebook
  • Registering a WINDEV application on Facebook
  • Registering an Android application on Facebook
  • Registering an iOS application on Facebook
  • Registering a WEBDEV site on Facebook
  • Configuring Facebook authentication in WINDEV, WINDEV Mobile and WEBDEV
  • Establishing the connection
  • Using the Facebook API
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Overview
Facebook is the world's most popular social network. It is commonly used by companies to reach their customers. Facebook includes a very powerful API to take full advantage of the platform.
WINDEV, WEBDEV and WINDEV Mobile include two modes to use Facebook for Android and iOS applications:
  • a simple mode that allows users to use their Facebook credentials to log in to the WINDEV or WINDEV Mobile application, or to the WEBDEV site. Users don't need to set a new password.
  • an advanced mode to interface with Facebook in order to use the Facebook API from a WINDEV or WINDEV Mobile application, or from a WEBDEV site.
The principle is the same regardless of the selected use mode. You must:
  • Register the WINDEV or WINDEV Mobile application, or the WEBDEV site on Facebook.
  • Use Facebook login credentials in the WINDEV or WINDEV Mobile application, or in the WEBDEV site.
  • Log in to Facebook from the WINDEV or WINDEV Mobile application, or from the WEBDEV site to authenticate.
For the advanced mode, you can use different WLanguage functions that allow you to interact with Facebook via its API.
Caution: This feature is not available for WINDEV applications in Linux.
Android Caution: This feature is available up to Android 11. Starting with Android 12, this function causes a fatal error.
It is recommended to:
Elements available in WLanguage
The following WLanguage elements can be used to interact with Facebook:
  • the fbSession type. This type of variable contains all the elements required to implement the Facebook connection and authentication .
  • several functions:
    FBGetUserInformationRetrieves the Facebook information of connected user.
    FBRequestPerforms a communication request (HTTP request) to the Facebook Graph API.
    FBSessionStatusChecks the status of a Facebook session.
    FBStartSessionUsed to authenticate and log in to Faceboook.
    FBStopSessionStops the Facebook session that was started by FBStartSession.
Registering the application on Facebook
WINDEV

Registering a WINDEV application on Facebook

First, it is necessary to create a Windows application in WINDEV using Facebook authentication and/or the Facebook API.
Let's see the steps to follow (valid at the time this page was written):
  1. Go to "https://developers.facebook.com/".
  2. Log in.
  3. Register if necessary and follow the steps.
  4. In "My Apps", click "Create App".
  5. In the page that appears, select "Consumer".
  6. Click "Next".
  7. In the page that is appears, specify:
    • The name of the application in "Add an app name".
    • A valid email address in "App contact email".
  8. Confirm the app creation (and validate the security check, if necessary).
  9. The page of the new app is displayed.
  10. Then, click the "Settings" menu and choose "Basic".
  11. Note down the "App ID" and "App secret".
  12. In the "App domains" field, type "localhost".
  13. At the bottom of the page, click on "Add platform" and select "Website".
  14. Enter the URL of the site: "http://localhost/".
  15. Then, click "Save changes".
The Facebook application is ready for testing.
At this point, you can log in to the application with the Facebook user who registered the application (administrator by default).
To include other users for testing, click the "Roles" menu and add the users with the relevant rights (developers, testers, etc.). You can also create test users ("Test Users" tab) to not use existing Facebook accounts.
To actually use the application, it must be set to public and be submitted to Facebook if necessary ("App Review" option). For more details, see the Facebook documentation.
Android

Registering an Android application on Facebook

First, it is necessary to create an Android application in WINDEV Mobile using Facebook authentication and/or the Facebook API.
Remark: Some elements required to create the Facebook application are provided in the Android application generation wizard ("Facebook" step). In order for the Facebook step to appear in the wizard, you must use a WLanguage function specific to Facebook.
Let's see the steps to follow (valid at the time this page was written):
  1. Go to "https://developers.facebook.com/".
  2. Log in.
  3. Register if necessary and follow the steps.
  4. In "My Apps", click "Create App".
  5. In the page that appears, select "Consumer".
  6. Click "Next".
  7. In the page that is appears, specify:
    • The name of the application in "Add an app name".
    • A valid email address in "App contact email".
  8. Confirm the app creation (and validate the security check, if necessary).
  9. The page of the new app is displayed.
  10. Then, click the "Settings" menu and choose "Basic".
  11. Note down the "App ID" and "App secret".
    The application identifier must be specified in the Android generation wizard ("Facebook" step).
  12. At the bottom of the page, click "Add platform" and select "Android".
  13. Specify:
    • the name of the application package (Google Play "Package Names" option). This name is provided in the Android generation wizard ("General information" or "Facebook" step).
    • the class name. This name is provided in the Android generation wizard ("Facebook" step).
    • the certificate hash key ("Key Hashes" option)
      Remark: You can find this information in the "Facebook" step when generating the Android application.
  14. Click "Save changes".
  15. Your application is saved.
iPhone/iPad

Registering an iOS application on Facebook

First, it is necessary to create an iOS application in WINDEV Mobile using Facebook authentication and/or the Facebook API.
Let's see the steps to follow (valid at the time this page was written):
  1. Go to "https://developers.facebook.com/".
  2. Log in.
  3. Register if necessary and follow the steps.
  4. In "My Apps", click "Create App".
  5. In the page that appears, select "Consumer".
  6. Click "Next".
  7. In the page that is appears, specify:
    • The name of the application in "Add an app name".
    • A valid email address in "App contact email".
  8. Confirm the app creation (and validate the security check, if necessary).
  9. The page of the new app is displayed.
  10. Then, click the "Settings" menu and choose "Basic".
  11. Note down the "App ID" and "App secret".
  12. At the bottom of the page, click "Add platform" and select "iOS".
  13. In "Bundle ID", enter the Bundle ID of your application. This name is provided in the iOS generation wizard ("General information" step).
  14. Click "Save changes".
  15. Your application is saved.
WEBDEV - Server code

Registering a WEBDEV site on Facebook

First, it is necessary to create a site in WEBDEV using Facebook authentication and/or the Facebook API.
Let's see the steps to follow (valid at the time this page was written):
  1. Go to "https://developers.facebook.com/".
  2. Log in.
  3. Register if necessary and follow the steps.
  4. In "My Apps", click "Create App".
  5. In the page that appears, select "Consumer".
  6. Click "Next".
  7. In the page that is appears, specify:
    • The name of the application in "Add an app name".
    • A valid email address in "App contact email".
  8. Confirm the app creation (and validate the security check, if necessary).
  9. The page of the new app is displayed.
  10. Then, click the "Settings" menu and choose "Basic".
  11. Note down the "App ID" and "App secret".
At this point, you can log in to the site with the Facebook user who registered the application (administrator by default).
To include other users for testing, click the "Roles" menu and add the users with the relevant rights (developers, testers, etc.). You can also create test users ("Test Users" tab) to not use existing Facebook accounts.
To actually use the application, it must be set to public and be submitted to Facebook if necessary ("App Review" option). For more details, see the Facebook documentation.
Configuring Facebook authentication in WINDEV, WINDEV Mobile and WEBDEV

Establishing the connection

To log in to Facebook, you must:
  1. Configure a Facebook session (fbSession variable). In the different proprerties of this variable, you must specify:
    • WINDEVWEBDEV - Server code the "App ID" and the "App secret" provided when registering the application on Facebook.
    • AndroidiPhone/iPad the "App ID" provided when registering the application on Facebook.
  2. Establish the connection with FBStartSession.
For example:
MyConnection is fbSession
// Configure the session
MyConnection.AppID = "1664XXXXXXXXXXXX"
MyConnection.AppSecret = "c6e7XXXXXXXXXXXXXXXXX"
// Define the rights:
// - Read the email
// - Manage the pages
MyConnection.Permission = [fbEmail, "manage_pages", "publish_pages", "publish_actions"]
// Connection
FBStartSession(MyConnection)
If the connection is permanent, the function does not show a login screen and opens the session directly.
Remarks:
  • WINDEVWEBDEV - Server code A Web page is displayed in the default browser, allowing users to enter their login credentials.
  • iPhone/iPad The function uses the Facebook account entered by the user on the phone (if it is specified).
  • Android The "public_profile" permission is always required when starting a Facebook session. If this permission was not specified in the list of permissions for the fbSession variable passed as parameter to FBStartSession, it will be automatically requested.
  • A started Facebook session is a persistent session: it will remain open:

Using the Facebook API

FBRequest is used to sent requests to Facebook.
The following example lists the pages and groups managed by the current user:
sURL is ANSI string = GRAPHAPI + "me/accounts?local=en_US"
sJSON is ANSI string
vJSON is Variant
 
// Retrieves the pages managed by the user
sJSON = FBRequest(MyConnection, sURL)
vJSON = JSONToVariant(sJSON)
The function returns the JSON response from Facebook.
Then, all you have to do is read and access the members documented in the Facebook API: "https://developers.facebook.com/docs/graph-api/reference".
FOR i = 1 _TO_ vJSON.data..Count
ListAdd(LIST_PAGES, gStoredValue(i) + vJSON.data[i].Name)
END
Minimum version required
  • Version 21
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 01/27/2023

Send a report | Local help