PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • Overview
  • The elements proposed by WLanguage
  • Declaring the application in Facebook
  • Declaring the Android application in Facebook
  • Declaring the iOS application 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
Caution: This feature is not available for the WINDEV applications in Linux.
New in version 22
Caution: This feature is not available for the WINDEV applications in Linux.
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
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 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)
    Remark: 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.
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:
    • WINDEV MobileAndroidiPhone/iPad the "App ID" supplied when registering the application to Facebook.
  2. Establish the connection with <fbSession variable>.Start.
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
MyConnection.Open()
 
If the connection is permanent, the function presents no connection screen and the session is started directly.
Remarks:
  • 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:

Using the Facebook API

<fbSession variable>.Request is used to perform requests toward Facebook.
The following example is used to list the pages and groups managed by the current user:
MyConnection is fbSession
...
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 = MyConnection.Request(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
LIST_PAGES.Add(gLink(i) + vJSON.data[i].Name)
END
Minimum version required
  • Version 24
This page is also available for…
Comments
Click [Add] to post a comment