PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
  • Overview
  • The elements proposed by WLanguage
  • Declaring the application in Facebook
  • Declaring the WINDEV application in Facebook
  • Declaring the Android application in Facebook
  • Declaring the iOS application in Facebook
  • Declaring the WEBDEV site in Facebook
  • Implementing the Facebook identification in the WINDEV or WINDEV Mobile application or in the WEBDEV site
  • 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/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Overview
Facebook, 1st social network in the world, is very much used by the companies to group their customers. Facebook includes a very powerful API to efficiently exploit the platform.
WINDEV, WEBDEV and WINDEV Mobile (for the Android and iOS applications) propose two modes for using Facebook:
  • a simple use, where the Facebook login of user can be used to identify in the WINDEV or WINDEV Mobile application or in the WEBDEV site. The end user will have less passwords to remember.
  • an advanced use, allowing you 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:
  • Declare the WINDEV or WINDEV Mobile application or the WEBDEV site to Facebook.
  • Use the Facebook identifiers in the WINDEV or WINDEV Mobile application or in the WEBDEV site.
  • Connect to Facebook from the WINDEV or WINDEV Mobile application or from the WEBDEV site to identify the user.
For an advanced use, several WLanguage functions allow you to communicate with Facebook via its API.
Versions 22 and later
WEBDEV - Server codeLinux This feature is now available for WEBDEV sites in Linux.
WEBDEV - Server codeWindows This feature is now available for WEBDEV sites in Windows.
Caution: This feature is not available for the WINDEV applications in Linux.
New in version 22
WEBDEV - Server codeLinux This feature is now available for WEBDEV sites in Linux.
WEBDEV - Server codeWindows This feature is now available for WEBDEV sites in Windows.
Caution: This feature is not available for the WINDEV applications in Linux.
WEBDEV - Server codeLinux This feature is now available for WEBDEV sites in Linux.
WEBDEV - Server codeWindows This feature is now available for WEBDEV sites in Windows.
Caution: This feature is not available for the WINDEV applications in Linux.
The elements proposed by WLanguage
The following WLanguage elements can be used to communicate with Facebook:
Declaring the application in Facebook
WINDEV

Declaring the WINDEV application in Facebook

A Facebook Windows application must be created beforehand.
Let's see the steps to follow (valid at the time this page was written):
  1. Connect to the "https://developers.facebook.com/" site.
  2. Identify yourself ("Connection" button).
  3. Register yourself if necessary (click the "Register" button and follow the wizard).
  4. In "My Apps", click "Create App".
  5. In the popup that appears, select "Consumer".
  6. Click "Next".
  7. In the popup that is displayed, specify:
    • In "App Display Name", enter the name of the application.
    • In "App Contact Email", enter a valid email address.
  8. Confirm the app creation (and validate the security check, if necessary).
  9. The page of the application that was just created 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" area, 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 declared the application (administrator by default).
To use other users for the tests, click the "Roles" menu and add the users with the relevant rights (developers, testers, ...). You also have the ability to create users for test ("Test users" tab) without using the existing Facebook accounts
For a real use of the application, the application must be made public and it must be submitted to Facebook if necessary ("Review apps" options). For more details, see the Facebook documentation.
Android

Declaring the Android application in Facebook

A Facebook Android application must be created beforehand.
Remark: Some elements required to create the Facebook application are supplied in the wizard for generating an Android application ("Facebook" screen). In order for the Facebook step to appear in this wizard, you must use a WLanguage function linked to Facebook.
Let's see the steps to follow (valid at the time this page was written):
  1. Connect to the "https://developers.facebook.com/" site.
  2. Identify yourself ("Connection" button).
  3. Register yourself if necessary (click the "Register" button and follow the wizard).
  4. In "My Apps", click "Create App".
  5. In the popup that appears, select "Consumer".
  6. Click "Next".
  7. In the popup that is displayed, specify:
    • In "App Display Name", enter the name of the application.
    • In "App Contact Email", enter a valid email address.
  8. Confirm the app creation (and validate the security check, if necessary).
  9. The page of the application that was just created 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 "Android".
  13. Specify:
    • the name of the application package ("Name of Google Play package" option). This name is given in the wizard for Android generation ("General information" screen or "Facebook" screen).
    • the class name. This name is given in the wizard for Android generation ("Facebook" screen).
    • the certificate hash key ("Key Hashes")
      Remark: This information can be found in the "Facebook" screen when generating the Android application.
  14. Click "Save Changes".
  15. Your application is saved.
iPhone/iPad

Declaring the iOS application in Facebook

A Facebook iOS application must be created beforehand.
Let's see the steps to follow (valid at the time this page was written):
  1. Connect to the "https://developers.facebook.com/" site.
  2. Identify yourself ("Connection" button).
  3. Register yourself if necessary (click the "Register" button and follow the wizard).
  4. In "My Apps", click "Create App".
  5. In the popup that appears, select "Consumer".
  6. Click "Next".
  7. In the popup that is displayed, specify:
    • In "App Display Name", enter the name of the application.
    • In "App Contact Email", enter a valid email address.
  8. Confirm the app creation (and validate the security check, if necessary).
  9. The page of the application that was just created 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 given in the wizard for iOS generation ("General information" screen).
  14. Click "Save Changes".
  15. Your application is saved.
Versions 22 and later
WEBDEV - Server code

Declaring the WEBDEV site in Facebook

A Facebook application must be created beforehand.
Let's see the steps to follow (valid at the time this page was written):
  1. Connect to the "https://developers.facebook.com/" site.
  2. Identify yourself ("Connection" button).
  3. Register yourself if necessary (click the "Register" button and follow the wizard).
  4. In "My Apps", click "Create App".
  5. In the popup that appears, select "Consumer".
  6. Click "Next".
  7. In the popup that is displayed, specify:
    • In "App Display Name", enter the name of the application.
    • In "App Contact Email", enter a valid email address.
  8. Confirm the app creation (and validate the security check, if necessary).
  9. The page of the application that was just created is displayed.
  10. Then, click the "Settings" menu and choose "Basic".
  11. Note down the "App ID" and "App Secret".
At this time, you have the ability to connect to the site with the Facebook user who declared the application (his administrator by default).
To use other users for the tests, click the "Roles" menu and add the users with the relevant rights (developers, testers, ...). You also have the ability to create users for test ("Test users" tab) without using the existing Facebook accounts
For a real use of the application, the application must be made public and it must be submitted to Facebook if necessary ("Review apps" options). For more details, see the Facebook documentation.
New in version 22
WEBDEV - Server code

Declaring the WEBDEV site in Facebook

A Facebook application must be created beforehand.
Let's see the steps to follow (valid at the time this page was written):
  1. Connect to the "https://developers.facebook.com/" site.
  2. Identify yourself ("Connection" button).
  3. Register yourself if necessary (click the "Register" button and follow the wizard).
  4. In "My Apps", click "Create App".
  5. In the popup that appears, select "Consumer".
  6. Click "Next".
  7. In the popup that is displayed, specify:
    • In "App Display Name", enter the name of the application.
    • In "App Contact Email", enter a valid email address.
  8. Confirm the app creation (and validate the security check, if necessary).
  9. The page of the application that was just created is displayed.
  10. Then, click the "Settings" menu and choose "Basic".
  11. Note down the "App ID" and "App Secret".
At this time, you have the ability to connect to the site with the Facebook user who declared the application (his administrator by default).
To use other users for the tests, click the "Roles" menu and add the users with the relevant rights (developers, testers, ...). You also have the ability to create users for test ("Test users" tab) without using the existing Facebook accounts
For a real use of the application, the application must be made public and it must be submitted to Facebook if necessary ("Review apps" options). For more details, see the Facebook documentation.
WEBDEV - Server code

Declaring the WEBDEV site in Facebook

A Facebook application must be created beforehand.
Let's see the steps to follow (valid at the time this page was written):
  1. Connect to the "https://developers.facebook.com/" site.
  2. Identify yourself ("Connection" button).
  3. Register yourself if necessary (click the "Register" button and follow the wizard).
  4. In "My Apps", click "Create App".
  5. In the popup that appears, select "Consumer".
  6. Click "Next".
  7. In the popup that is displayed, specify:
    • In "App Display Name", enter the name of the application.
    • In "App Contact Email", enter a valid email address.
  8. Confirm the app creation (and validate the security check, if necessary).
  9. The page of the application that was just created is displayed.
  10. Then, click the "Settings" menu and choose "Basic".
  11. Note down the "App ID" and "App Secret".
At this time, you have the ability to connect to the site with the Facebook user who declared the application (his administrator by default).
To use other users for the tests, click the "Roles" menu and add the users with the relevant rights (developers, testers, ...). You also have the ability to create users for test ("Test users" tab) without using the existing Facebook accounts
For a real use of the application, the application must be made public and it must be submitted to Facebook if necessary ("Review apps" options). For more details, see the Facebook documentation.
Implementing the Facebook identification in the WINDEV or WINDEV Mobile application or in the WEBDEV site

Establishing the connection

To connect 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" supplied when registering the application to Facebook.
    • AndroidiPhone/iPad the "App ID" supplied when registering the application to 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 presents no connection screen and the session is started directly.
Remarks:
  • WINDEVWEBDEV - Server code A Web page is displayed in the default browser, allowing the user to type his login and password.
  • iPhone/iPad The function is using the Facebook account entered by the user on the phone (if this account 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 in parameter to FBStartSession, this permission will be automatically requested.
  • A started Facebook session is a persistent session: it will remain opened:
    • until the application is closed.
    • until the call to FBStopSession.

Using the Facebook API

FBRequest is used to perform requests toward Facebook.
The following example is used to list 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 of 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..Occurrence
ListAdd(LIST_PAGES, gLink(i) + vJSON.data[i].name)
END
Minimum version required
  • Version 21
This page is also available for…
Comments
Click [Add] to post a comment