PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • 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 the WEBDEV sites in Linux.
WEBDEV - Server codeWindows This feature is now available for the 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 the WEBDEV sites in Linux.
WEBDEV - Server codeWindows This feature is now available for the 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 the WEBDEV sites in Linux.
WEBDEV - Server codeWindows This feature is now available for the 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 the "My Apps" menu, click "Add an App".
  5. In the popup that is displayed, specify:
    • The name of your application in the "Usage name" control.
    • A valid email address in the "Email address of contact" control.
  6. Click the "Create an app ID" button.
  7. The page of the application that was just created is displayed.
  8. Display the dashboard of the application.
  9. Write down the "App ID" and the "Secret key".
  10. Then, click the "Settings" menu and choose "General".
  11. In the "App domains" area, type "localhost".
  12. Click "Add a platform" and select "Website".
  13. Type "http://localhost/".
  14. Then, click the "Save the modifications" button.
The Facebook application is ready for tests.
At this time, you have the ability to connect to the application 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). See the Facebook documentation for more details.
Android

Declaring the Android application in Facebook

A Facebook Android application must be created beforehand.
Note: 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 the "My Apps" menu, click "Add an App".
  5. In the popup that is displayed, specify:
    • The name of your application in the "Usage name" control.
    • A valid email address in the "Email address of contact" control.
  6. Click the "Create an app ID" button.
  7. The page of the application that was just created is displayed.
  8. Display the dashboard of the application.
  9. Write down the "App ID" and the "Secret key".
  10. Then, click the "Settings" menu and choose "General".
  11. Click "Add a platform" and select "Android".
  12. 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).
  13. the hash key of certificate ("Key hashing" option)
    Note: This information can be found in the "Facebook" screen when generating the Android application.
  14. Click "Save the modifications".
  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 the "My Apps" menu, click "Add an App".
  5. In the popup that is displayed, specify:
    • The name of your application in the "Usage name" control.
    • A valid email address in the "Email address of contact" control.
  6. Click the "Create an app ID" button.
  7. The page of the application that was just created is displayed.
  8. Display the dashboard of the application.
  9. Write down the "App ID".
  10. Then, click the "Settings" menu and choose "General".
  11. Click "Add a platform" and select "iOS".
  12. In the "Pack ID" area, sepcify the Bundle identifier of your application. This name is given in the wizard for iOS generation ("General information" screen).
  13. Click "Save the modifications".
  14. 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 the "My Apps" menu, click "Add an App".
  5. In the popup that is displayed, specify:
    • The name of your application in the "Usage name" control.
    • A valid email address in the "Email address of contact" control.
  6. Click the "Create an app ID" button.
  7. The page of the application that was just created is displayed.
  8. Display the dashboard of the application.
  9. Write down the "App ID" and the "Secret key".
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). See the Facebook documentation for more details.
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 the "My Apps" menu, click "Add an App".
  5. In the popup that is displayed, specify:
    • The name of your application in the "Usage name" control.
    • A valid email address in the "Email address of contact" control.
  6. Click the "Create an app ID" button.
  7. The page of the application that was just created is displayed.
  8. Display the dashboard of the application.
  9. Write down the "App ID" and the "Secret key".
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). See the Facebook documentation for more details.
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 the "My Apps" menu, click "Add an App".
  5. In the popup that is displayed, specify:
    • The name of your application in the "Usage name" control.
    • A valid email address in the "Email address of contact" control.
  6. Click the "Create an app ID" button.
  7. The page of the application that was just created is displayed.
  8. Display the dashboard of the application.
  9. Write down the "App ID" and the "Secret key".
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). See the Facebook documentation for more details.
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.
    • WINDEV MobileAndroidiPhone/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.
Notes:
  • WINDEV A window allowing the user to type his login and password is automatically displayed. 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.
iPhone/iPad 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 required version
  • Version 21
This page is also available for…
Comments
Click [Add] to post a comment